package com.company;

import java.util.ArrayList;

/**
 *This class is used by the company for adding new airplanes to the system or adding and removing flights.
 * @author Seyedeh Fatemeh Ahmadzadeh
 * @version 1.0
 * @since 2019 - 3 - 5
 */

public class Operator {

    private ArrayList<Flight> flights = new ArrayList<Flight>();
    private ArrayList<Airplain> airplains = new ArrayList<Airplain>();

    /**
     * Makes a new flight and then add it to the list of flights
     * @param date the date of the flight
     * @param time the time of the flight
     * @param flightNo the number of the flight
     * @param source the source of the flight
     * @param destination the destination of the flight
     * @param airplain the airplane of the flight
     * @param airline the airline of the flight
     */

    public void addFlight(String date , String time , int flightNo , String source , String destination , Airplain airplain , String airline){
        Flight f = new Flight(date , time , flightNo , source , destination , airplain , airline);
        flights.add(f);
    }

    /**
     * Another way for adding a flight.
     * @param flight the new flight.
     */

    public void addFlight(Flight flight){
        flights.add(flight);
    }
    /**
     * This method adds a new airplane to the system.
     * @param airplaneKind is the type of new airplane
     */

    public void addAirplaine(String airplaneKind){
        Airplain a = new Airplain(airplaneKind);
        airplains.add(a);
    }

    /**
     * This method is used when we have added a new airplane and we want to set and specify its seats.
     * @param seatKind is the type of the seat
     * @param seatNumber is the number of the seat
     * @param airplane is the new airplane that we have added recently.
     */

    public void addSeat(String seatKind , int seatNumber , Airplain airplane){
        Seat s = new Seat(seatKind , seatNumber);
        for(Airplain a : airplains){
            if(a.equals(airplane)) {
                a.setSeat(s);
                break;
            }
        }
    }

    /**
     * Another way to add an airplane to the system
     * @param airplain the new airplane
     */

    public void addAirplane(Airplain airplain){
        airplains.add(airplain);
    }

    /**
     * This method is used to check the flights in other classes.
     * @return all available flights
     */

    public ArrayList<Flight> getFlights(){
        return flights;
    }

    /**
     * Returns an array list of all the airplanes
     * @return the array list of airplanes
     */

    public ArrayList<Airplain> getAirplains(){
        return airplains;
    }

    /**
     * Removes a cancelled flight from the list of flights.
     * @param flight is the cancelled flight
     */

    public void removeFlight(Flight flight){
        for(Flight f : flights){
            if(f.equals(flight)){
                flights.remove(flight);
                break;
            }
        }
    }
}
