/*
 * @topic T02705 Assignment a8 -- Airline Flight Schedule demo Verion 2
 * @brief Airline Flight Schedule Prototype as of Fri, Dec 14, 2012
*/
package airlinesV2;

public class Main {

    public static void main(String[] args) {

        FlightSchedule schedule = new FlightSchedule();
        AirlineReports reports = new AirlineReports(schedule);

        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 code = menu.getString("Airline code:");
                    if ( schedule.isValidAirlineCode( code ) == true ) {
                        System.out.println("\t *** Airline "+code+" is already on file, please retry." );
                        break;
                    }
                    schedule.addAirline(code);
                    System.out.println("\tAirline "+code+" added successfully." );
                    break;
                }
                case UserMenu.MENU_CHOICE_SHOW_AIRLINES:
                {
                    reports.showAirlines();
                    break;
                }
                //--------------------------------
                case UserMenu.MENU_CHOICE_ADD_FLIGHT:
                {
                    String code = menu.getString("Airline code: ");
                    if ( schedule.isValidAirlineCode( code ) == false ) {
                        System.out.println("\t *** Airline "+code+" is not on file, please retry." );
                        break;
                    }
                    int flightNumber = menu.getInt("Flight number: ");
                    if ( schedule.isExistingFlightNumber( code, flightNumber ) ) {
                        System.out.println("\t *** This flight is already scheduled, please retry." );
                        break;
                    }
                    Flight flight = schedule.addFlight( code, flightNumber);
                    if ( flight == null ) {
                        System.out.println("\t *** Airline "+code+" is not on file, please retry." );
                    } else {
                        System.out.println(
                                "\t *** Flight "
                                +
                                flight.getExternalFlightNumber()
                                +
                                " added successfully." );
                    }
                    break;
                }
            }//switch
            menu.pause( "\tPress Enter to continue:" );
        }//for

    }//main
}//class Main