package h05;

public class CombinedPlane extends Plane implements CarriesCargo, CarriesPassengers{

    protected static final char AVERAGE_PEOPLE_WEIGHT = 100;
    protected static final char AVERAGE_LUGGAGE_WEIGHT = 15;

    private final int crewCount;

    private int passengerCount = 0;

    public CombinedPlane(String aircraftRegistration, int baseWeight, FuelType fuelType, double fuelCapacity, int crewCount) {
        super(aircraftRegistration, baseWeight, fuelType, fuelCapacity);
        this.crewCount = crewCount;
    }

    @Override
    protected double mass() {
        return containers.getSum() + getBaseWeight() + passengerCount * AVERAGE_LUGGAGE_WEIGHT + passengerCount * AVERAGE_PEOPLE_WEIGHT + crewCount * AVERAGE_PEOPLE_WEIGHT;
    }

    @Override
    public void board(int passengers) {
        passengerCount += passengers;
    }

    @Override
    public void disembark() {
        passengerCount = 0;
    }

    @Override
    public int getPassengerCount() {
        return passengerCount;
    }

    private final CargoStack containers = new CargoStack();

    @Override
    public void loadContainer(int cargoWeight) {
        containers.push(cargoWeight);
    }

    @Override
    public boolean hasFreightLoaded() {
        return !containers.empty();
    }

    @Override
    public int unloadNextContainer() {
        return containers.pop();
    }
}
