package h05;

import java.util.stream.DoubleStream;

public class TankerPlane extends Plane implements Refuelling {

    private final double[] availableAmount = new double[FuelType.values().length];

    public TankerPlane(String aircraftRegistration, int baseWeight, FuelType fuelType, double fuelCapacity) {
        super(aircraftRegistration, baseWeight, fuelType, fuelCapacity);
    }

    @Override
    protected double mass() {
        return getBaseWeight() + DoubleStream.of(availableAmount).sum();
    }

    @Override
    public void refuelPlane(Plane plane) {
        var diff = plane.getFuelCapacity() - plane.getCurrentFuelLevel();
        var avail = availableAmount[plane.getFuelType().ordinal()];

        if (diff > avail) {
            System.out.println("auawuduiwahduihdauwihdw");
            return;
        }

        plane.refuel(diff);
        availableAmount[plane.getFuelType().ordinal()] -= diff;
    }

    public void loadFuel(FuelType type, double amount) {
        availableAmount[type.ordinal()] = amount;
    }
}
