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

public class Flight implements Comparable< Flight > {

    private Airline airline;
    private int flightNumber;
    private char status; // C=cancelled S=scheduled, ...
    private char type;  // D=domestic, I=international
    private DepartureArrivalInfo departureInfo;
    private DepartureArrivalInfo arrivalInfo;
    
    static public final int SORT_BY_DEPARTURE_TIME = 1;
    static public final int SORT_BY_ARRIVAL_TIME = 2;
    static private int sortBy = SORT_BY_DEPARTURE_TIME;
    
    static public void setSortBy( int sortBy ) {
        Flight.sortBy = sortBy;
    }
    
    static public int getSortBy() {
        return sortBy;
    }
    // constructors
    public Flight(
            Airline airline,
            int flightNumber,
            char status,
            char type,
            DepartureArrivalInfo departureInfo,
            DepartureArrivalInfo arrivalInfo
    ) {
        this.airline = airline;
        this.flightNumber = flightNumber;
        this.status = status;
        this.type = type;
        this.departureInfo = departureInfo;
        this.arrivalInfo = arrivalInfo;
    }

    // operations
    public Airline getAirline() {
        return airline;
    }

    public int getFlightNumber() {
        return flightNumber;
    }

    public char getStatus() {
        return status;
    }

    public char getType() {
        return type;
    }

    public DepartureArrivalInfo getDepartureInfo() {
        return departureInfo;
    }

    public DepartureArrivalInfo getArrivalInfo() {
        return arrivalInfo;
    }
    
    @Override
    public int compareTo( Flight another ) {
        int myTime = 0;
        int anotherTime = 0;
        if ( Flight.getSortBy() == Flight.SORT_BY_DEPARTURE_TIME ) {
            myTime = this.departureInfo.getTime();
            anotherTime = another.departureInfo.getTime();
        } else {
            myTime = this.arrivalInfo.getTime();
            anotherTime = another.arrivalInfo.getTime();
        }
        if ( myTime < anotherTime ) {
            return -1; // this < another
        } else if ( myTime == anotherTime ) {
            return 0;  // this == another
        } else {
            return 1;  // this > another
        }
    }
    
}//class Flight