#pragma once

#include <string>
#include <unordered_map>
#include <nlohmann/json.hpp>
#include "warfactory/ResourceRegistry.h"

using json = nlohmann::json;

namespace warfactory {

/**
 * @brief Represents a volcanic formation with lifetime resource reservoir
 *
 * Models a complete volcano lifecycle spanning millions of years, not just single eruptions.
 * Contains total material reservoir that will be ejected over the volcano's entire active period.
 * Composition based on planetary core materials filtered by melting points.
 */
class Volcano {
public:
    enum class VolcanoType {
        SHIELD,        // Low-profile, fluid lava (like Mauna Loa)
        STRATOVOLCANO, // Steep-sided, explosive (like Mount Fuji)
        CALDERA,       // Large crater from major eruption (like Yellowstone)
        CINDER_CONE    // Small, simple cone (like Paricutin)
    };

private:
    uint32_t volcano_id;
    VolcanoType type;
    std::unordered_map<uint32_t, uint64_t> total_reservoir; // Resource ID -> total tonnes over lifetime
    float x_position, y_position;
    double formation_time;           // When volcano was created (years)

public:
    Volcano();
    Volcano(const json& volcano_data);

    // ========================================
    // VOLCANO PROPERTIES
    // ========================================

    uint32_t getVolcanoId() const { return volcano_id; }
    void setVolcanoId(uint32_t id) { volcano_id = id; }

    VolcanoType getType() const { return type; }
    void setType(VolcanoType volcano_type) { type = volcano_type; }

    float getXPosition() const { return x_position; }
    float getYPosition() const { return y_position; }
    void setPosition(float x, float y) { x_position = x; y_position = y; }


    double getFormationTime() const { return formation_time; }
    void setFormationTime(double time) { formation_time = time; }

    // ========================================
    // RESOURCE RESERVOIR MANAGEMENT
    // ========================================

    /**
     * @brief Get total lifetime reservoir composition
     */
    const std::unordered_map<uint32_t, uint64_t>& getTotalReservoir() const { return total_reservoir; }


    /**
     * @brief Add resource to volcano's lifetime reservoir
     * @param resource_id Resource to add
     * @param quantity Total quantity over volcano lifetime
     */
    void addResourceToReservoir(uint32_t resource_id, uint64_t quantity);

    /**
     * @brief Calculate total reservoir mass (all resources combined)
     * @return Total mass in tonnes
     */
    uint64_t getTotalReservoirMass() const;


    // ========================================
    // VOLCANIC ACTIVITY SIMULATION
    // ========================================

    /**
     * @brief Create a copy of this volcano
     */
    Volcano copy() const;

    // ========================================
    // UTILITY
    // ========================================

    /**
     * @brief Convert volcano type enum to string
     */
    static std::string typeToString(VolcanoType type);

    /**
     * @brief Convert string to volcano type enum
     */
    static VolcanoType stringToType(const std::string& type_str);

private:
};

} // namespace warfactory