import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;


public class ReserveMenu extends BasicMenu implements Menu 
{
	private List<Room> rooms;
	public ReserveMenu(Menu parent)
	{
		super(parent);
	}
	
	public boolean executeMenu(){
        rooms = Room.getRooms();
        String output = "";
        String info = "";
	        
        output += "0) Go to previous menu\n";
       
        for(int i = 0; i < rooms.size(); i++) {
        	output += (i+1) + ") " + rooms.get(i).getId() + "\n";
        }
        
        info += "Please select room to reserve.";
        
        GUI.setOutputTextArea(output);
        GUI.setInfoMessage(info);
        
        return true;

	}
	
	public boolean processInput(String str)
	{
		try {
			int choice = Integer.parseInt(str);

			if(choice == 0) {
				MenuSystem.setCurrentMenu(parent);
				parent.executeMenu();
				return false;
			}
			ReserveRoomHandler.makeReservation(rooms.get(choice - 1), HandleAuthorization.getCurrentUser());
			
		} catch (IndexOutOfBoundsException e) {
	    	GUI.setErrorMessage("Please enter an integer in the range: [0-" + rooms.size() + "].");
	    } catch (NumberFormatException e) {
	    	GUI.setErrorMessage("Please enter an integer value.");
	    } catch (NoRoomException e) {
	    	//No rooms available
	 	}
        
	    return true;
	}
}
