/*
 * @topic T02725 Assignment a8 -- Airline Flight Schedule demo Verion 2
 * @brief class Flight implements Comparable
*/
package airlinesV2;
import java.util.ArrayList;

public class Flight implements Comparable {
    public static final int SCHEDULE_SORT_ORDER_DEPARTURE_TIME = 1;
    public static final int SCHEDULE_SORT_ORDER_ARRIVAL_TIME = 2;
    public static final int SCHEDULE_SORT_ORDER_DEPARTURE_GATE = 3;
    private static int sortOrder = SCHEDULE_SORT_ORDER_DEPARTURE_TIME;
    int someData = 0;
    String airlineCode;
    int flightNumber;

    // constructors
    public Flight( String airlineCode, int flightNumber )
    {
        this.airlineCode = airlineCode;
        this.flightNumber = flightNumber;
    }

    // operations
    public void updateStatus( char status )
    {
    }

    public int compareTo( Object other )
    {
        // TODO: proceed according to the sortOrder
        Flight otherFlight = ( Flight ) other;
        if ( someData < otherFlight.someData ) {
            return -1;
        } else if ( someData > otherFlight.someData ) {
            return +1;
        }
        return 0;
    }

    // returns true if success, false otherwise
    public boolean assignDepartureGate( String gate, FlightSchedule schedule ) {

        // NOTE: this will not compile as is !!!
        // This is just a "pseudocode"

        DepartureArrivalInfo thisFlightinfo = getDepartureInfo();
        String airport = thisFlightinfo.getAirport(); // daparture airport
        char weekDay = thisFlightinfo.getDayOfWeek(); // daparture day

        ArrayList<Flight> departures =
                schedule.getSortedDepartures(/*airport, weekDay*/);

        for( Flight other : departures ) {
            DepartureArrivalInfo otherFlightinfo = other.getDepartureInfo();
            if (
                    otherFlightinfo.getTime() == thisFlightinfo.getTime()
                    && // logical AND
                    0 == otherFlightinfo.getGate().compareTo(gate)
                    )
            {
                // same day/time and gate should not be allowed:
                return false;
            }
        }
        thisFlightinfo.setGate( gate );
        return true;
    }

    public DepartureArrivalInfo getDepartureInfo()
    {
        return new DepartureArrivalInfo();
    }

    public String getExternalFlightNumber()
    {
        return airlineCode + flightNumber;
    }

}//class Flight