package uebung05.logistics;

import uebung05.logistics.material.BulletBelts;
import uebung05.logistics.material.LiterDiesel;
import uebung05.logistics.quantities.FloatUnit;
import uebung05.logistics.quantities.IntUnit;
import uebung05.logistics.quantities.NeedCollector;
import uebung05.logistics.storage.FloatStorage;
import uebung05.logistics.storage.IntStorage;

/**
 * The Truck class represents a truck in the logistics system.
 * It extends the Vehicle abstract class and includes a tank for diesel, a storage for bullet belts, and the necessary methods for reporting needs, filling up, and consuming supplies.
 *
 * @author Nikolaus Köberlein
 * @version 1.0
 */
public class Truck extends Vehicle {

    FloatStorage tank;
    IntStorage bullets;

    private final static int maxAmmunition = 3;
    private final static int maxFuel = 180;

    /**
     * Construct a Truck object with a name, diesel amount, and bullet belts amount
     *
     * @param name            The name of the truck
     * @param diesel          The initial amount of diesel for the truck
     * @param bulletBelts     The initial amount of bullet belts for the truck
     */
    public Truck(String name, float diesel, int bulletBelts) {
        super(name, 3, 3);

        tank = new FloatStorage(diesel, LiterDiesel.getINSTANCE(), maxFuel);
        bullets = new IntStorage(bulletBelts, BulletBelts.getINSTANCE(), maxAmmunition);
    }

    /**
     * Construct a Truck object with a name, diesel amount, and bullet belts amount
     *
     * @param name            The name of the truck
     */
    public Truck(String name) {
        this(name, 0, 0);
    }

    /**
     * Report the needs of the truck to a NeedCollector object
     *
     * @param collector The NeedCollector object to which to report the needs
     */
    @Override
    public void reportNeeds(NeedCollector collector) {
        tank.reportNeed(collector);
        bullets.reportNeed(collector);
        super.reportBasicNeeds(collector);
    }

    /**
     * Fill up all the supplies for the truck
     */
    @Override
    public void fillUpAll() {
        tank.fillUp();
        bullets.fillUp();
        super.fillUpBasic();
    }

    /**
     * Consume the truck's supplies based on the intensity rate
     *
     * @param intensityRate The intensity rate for the consumption
     */
    @Override
    public void consumeAll(int intensityRate) {
        tank.consume(intensityRate*25);
        bullets.consume(intensityRate*2);
        super.consumeBasic();
    }

    /**
     * Check if the truck needs a specific IntUnit object
     *
     * @param unit The IntUnit object for which to check the need
     * @return True if the truck needs the IntUnit object, false otherwise
     */
    @Override
    public Boolean need(IntUnit unit) {
        return unit == bullets.getUnit() || unit == oil.getUnit() || unit == grease.getUnit();
    }

    /**
     * Check if the truck needs a specific FloatUnit object
     *
     * @param unit The FloatUnit object for which to check the need
     * @return True if the truck needs the FloatUnit object, false otherwise
     */
    @Override
    public Boolean need(FloatUnit unit) {
        return unit == tank.getUnit();
    }
}