#pragma once

#include "ASerializable.h"
#include <unordered_map>
#include <string>

namespace warfactory {

class PlanetaryCore : public ASerializable {
private:
    float core_mass;
    float core_temperature_celsius;
    float max_core_capacity;
    std::unordered_map<std::string, float> composition;

public:
    PlanetaryCore();
    PlanetaryCore(float initial_mass, float initial_temperature, float max_capacity);

    float getCoreMass() const { return core_mass; }
    void setCoreMass(float mass) { core_mass = mass; }

    float getCoreTemperature() const { return core_temperature_celsius; }
    void setCoreTemperature(float temperature) { core_temperature_celsius = temperature; }

    float getMaxCoreCapacity() const { return max_core_capacity; }
    void setMaxCoreCapacity(float capacity) { max_core_capacity = capacity; }

    float getRemainingCapacity() const { return max_core_capacity - core_mass; }
    bool hasCapacityFor(float additional_mass) const { return (core_mass + additional_mass) <= max_core_capacity; }

    const std::unordered_map<std::string, float>& getComposition() const { return composition; }

    void addMaterial(const std::string& material_type, float quantity);
    void removeMaterial(const std::string& material_type, float quantity);
    float getMaterialQuantity(const std::string& material_type) const;
    bool hasMaterial(const std::string& material_type) const;

    void updateMass();

    void coolDown(float cooling_rate_per_cycle);
    void heatUp(float heating_amount);

    float getCoreOverflowPressure() const;
    bool shouldOverflow(float pressure_threshold) const;

    json serialize() const override;
    void deserialize(const json& data) override;

    void reset();
};

} // namespace warfactory