/*
 * @topic T03705 <hr />Assignment a8 -- Fall 2015<hr />
 * @brief Main class
*/
package airlinesV2;

public class Main {

    public static void main(String[] args) {

        FlightSchedule schedule = new FlightSchedule();

        UserMenu menu = new UserMenu();
        menu.attach(" 1. Set Clock");
        menu.attach(" 2. Delete all existing Aircraft/Flight Schedule records and start over");
        menu.attach(" 3. Add Airline/Aircraft");
        menu.attach(" 4. Show Airlines");
        menu.attach(" 5. Add Flight");
        menu.attach(" 6. Cancel Flight");
        menu.attach(" 7. Show Flight Info");
        menu.attach(" 8. Show all departures for a particular Airport on a given day-of-the-week");
        menu.attach(" 9. Show all arrived flights and scheduled arrivals for a particular Airport on a given day-of-the-week");
        menu.attach("10. Find flights between two Airports");
        menu.attach("11. Exit");

        for (;;) { // forever
            int choice = menu.getUserChoice();
            switch (choice) {
                //--------------------------------
                case UserMenu.MENU_CHOICE_EXIT:
                    System.exit(0);

                //--------------------------------
                case UserMenu.MENU_CHOICE_ADD_AIRLINE: {
                    String name = menu.getString("Airline name: ");
                    String code = menu.getString("Airline code: ");
                    if (schedule.doesArilineCodeExist(code)) {
                        System.out.println("\tSorry, airline code [" + code + "] already exists.");
                        break;
                    }
                    schedule.addAirline(name, code);
                    System.out.println("\tAirline " + code + " added successfully.");
                    break;
                }
                case UserMenu.MENU_CHOICE_ADD_FLIGHT: {
                    String airlineCode = menu.getString("Airline code: ");
                    Airline airline = schedule.lookupAirline(airlineCode);
                    if (airline == null) {
                        System.out.println("\tSorry, airline code [" + airlineCode + "] is not on file.");
                        break;
                    }
                    int flightNumber = 100 + (int) (Math.random() * 300); // pretend the user has entered the number
                    char status = 'S'; // C=cancelled S=scheduled, ...
                    char type = 'D';  // D=domestic, I=international

                    String airport = menu.getString("Departure Airport: ");;
                    String gate = "A" + (1 + (int) (Math.random() * 40));
                    char dayOfWeek = 'M';
                    int time = 1111;

                    DepartureArrivalInfo departureInfo = new DepartureArrivalInfo(airport, gate, dayOfWeek, time);
                    airport = menu.getString("Arrival Airport: ");;
                    gate = "B" + (1 + (int) (Math.random() * 40));
                    dayOfWeek = 'M';
                    time = 2222;
                    DepartureArrivalInfo arrivalInfo = new DepartureArrivalInfo(airport, gate, dayOfWeek, time);
                    Flight flight = new Flight(
                            airline,
                            flightNumber,
                            status,
                            type,
                            departureInfo,
                            arrivalInfo
                    );
                    schedule.addFlight(airline.getCode() + flightNumber, flight);
                    break;
                }
                case UserMenu.MENU_CHOICE_SHOW_AIRLINES:
                    schedule.displayAirlines();
                    break;

                case UserMenu.MENU_CHOICE_SHOW_DEPARTURES:
                    schedule.displayDepartures("BOS", 'M');
                    break;

                default:
                    System.out.println("\tSorry, this function is under development...");
                    break;

            }//switch
            menu.pause("\tPress Enter to continue:");
        }//for

    }//main
}//class Main