package uebung05.logistics.quantities;

import uebung05.logistics.material.BulletBelts;
import uebung05.logistics.material.Grease;
import uebung05.logistics.material.LiterDiesel;
import uebung05.logistics.material.MetGallonsKerosene;
import uebung05.logistics.material.Oil;
import uebung05.logistics.material.RocketPods;
import uebung05.logistics.material.ShellBatches;

import java.util.HashMap;
import java.util.Map;

/**
 * The NeedCollector class is responsible for storing and managing the needed supplies for vehicles.
 * It contains two maps, intNeeded and floatNeeded, to store the needed supplies.
 * Users can add an integer or float amount of a specific unit to the maps using the add method.
 * The getNeed method can be used to retrieve the integer or float amount needed for a specific unit.
 * The show method prints the needed supplies for all vehicles.
 *
 * @author Nikolaus Köberlein
 * @version 1.0
 */
public class NeedCollector {

    // Maps to store the needed supplies for vehicles
    private Map<IntUnit, Integer> intNeeded;
    private Map<FloatUnit, Float> floatNeeded;

    /**
     * Initialize the two maps for storing the needed supplies
     */
    public NeedCollector() {
        intNeeded = new HashMap<>();
        floatNeeded = new HashMap<>();
    }

    /**
     * Add an integer amount of a specific IntUnit to the intNeeded map
     *
     * @param amount The integer amount to be added
     * @param unit   The IntUnit to which the amount belongs
     */
    public void add(int amount, IntUnit unit) {
        intNeeded.merge(unit, amount, Integer::sum);
    }

    /**
     * Add a float amount of a specific FloatUnit to the floatNeeded map
     *
     * @param amount The float amount to be added
     * @param unit   The FloatUnit to which the amount belongs
     */
    public void add(float amount, FloatUnit unit) {
        floatNeeded.merge(unit, amount, Float::sum);
    }

    /**
     * Get the integer amount needed for a specific IntUnit
     *
     * @param unit The IntUnit for which the amount is needed
     * @return The integer amount needed for the specified unit
     */
    public int getNeed(IntUnit unit) {
        return intNeeded.getOrDefault(unit, 0);
    }

    /**
     * Get the float amount needed for a specific FloatUnit
     *
     * @param unit The FloatUnit for which the amount is needed
     * @return The float amount needed for the specified unit
     */
    public float getNeed(FloatUnit unit) {
        return floatNeeded.getOrDefault(unit, 0.0f);
    }

    /**
     * Print the needed supplies for all vehicles
     */
    public void show() {
        System.out.println("Needed supplies for all vehicles:");

        // Print the needed supplies for specific units
        System.out.println("- " + getNeed(Grease.getINSTANCE()) + " " + Grease.getINSTANCE());
        System.out.println("- " + getNeed(ShellBatches.getINSTANCE()) + " " + ShellBatches.getINSTANCE());
        System.out.println("- " + getNeed(RocketPods.getINSTANCE()) + " " + RocketPods.getINSTANCE());
        System.out.println("- " + getNeed(BulletBelts.getINSTANCE()) + " " + BulletBelts.getINSTANCE());
        System.out.println("- " + getNeed(Oil.getINSTANCE()) + " " + Oil.getINSTANCE());
        System.out.println("- " + getNeed(MetGallonsKerosene.getINSTANCE()) + " " + MetGallonsKerosene.getINSTANCE());
        System.out.println("- " + getNeed(LiterDiesel.getINSTANCE()) + " " + LiterDiesel.getINSTANCE());

        //todo
        /*
        for (Map.Entry<IntUnit, Integer> entry : collector.getIntNeeded().entrySet()) {
            IntUnit unit = entry.getKey();
            int amount = entry.getValue();

        }

        for (FloatUnit unit : FloatUnit.getAllUnits()) {
            float totalNeed = collector.getNeed(unit);
            System.out.println("- " + totalNeed + " " + unit.toString());
        }*/
        System.out.println();
    }

}