#pragma once

#include "../WorldGenerationFunctions/IWorldGenerationFunction.h"
#include "../MeteoriteFactory.h"
#include "../Meteorite.h"
#include <vector>
#include <memory>
#include <map>
#include <string>

namespace warfactory {

/**
 * @brief Generate meteorite impacts for geological simulation
 *
 * Producer in the Producer/Consumer pattern. Generates batches of meteorites
 * using MeteoriteFactory based on configuration parameters like impact frequency,
 * type weights, and size bias.
 */
class MeteoriteImpactGenerationFunction : public IWorldGenerationFunction {
private:
    MeteoriteFactory meteorite_factory;

    // Configuration parameters
    int min_impacts_per_wave;
    int max_impacts_per_wave;
    std::string meteorite_source;
    std::string size_bias;
    std::map<std::string, float> type_weights;
    float impact_probability_per_cycle;  // Optional parameter for some phases

    // Generated meteorites storage
    std::vector<std::unique_ptr<Meteorite>> generated_meteorites;

public:
    MeteoriteImpactGenerationFunction();

    // Inherited from IWorldGenerationFunction
    void configure(const IDataNode& config) override;
    void execute(WorldData& world, PlanetaryCore& core) override;
    std::string getStepName() const override;
    bool isConfigured() const override;
    void reset() override;

    /**
     * @brief Get generated meteorites for consumption by other functions
     * @return Vector of generated meteorites (ownership transferred)
     */
    std::vector<std::unique_ptr<Meteorite>> extractGeneratedMeteorites();

private:
    /**
     * @brief Configure MeteoriteFactory with loaded parameters
     */
    void configureMeteoriteFactory();

    /**
     * @brief Generate batch of meteorites for current wave
     */
    void generateMeteoriteWave();

    /**
     * @brief Calculate number of impacts for this wave
     */
    int calculateImpactsThisWave() const;
};

} // namespace warfactory