#pragma once

#include "IWorldGenerationPhase.h"
#include "WorldData.h"
#include "warfactory/IDataNode.h"
#include <vector>
#include <memory>

namespace warfactory {

class WorldGenerationOrchestrator {
private:
    std::vector<std::unique_ptr<IWorldGenerationPhase>> phases;
    WorldData world_data;

    size_t current_phase_index;
    bool generation_complete;

public:
    WorldGenerationOrchestrator();
    ~WorldGenerationOrchestrator() = default;

    void loadConfiguration(const IDataNode& config);

    bool executeNextPhase(const IDataNode& config);

    bool executeAllPhases(const IDataNode& config);

    float getOverallProgress() const;

    bool isGenerationComplete() const { return generation_complete; }

    const WorldData& getWorldData() const { return world_data; }

    size_t getCurrentPhaseIndex() const { return current_phase_index; }

    size_t getTotalPhases() const { return phases.size(); }

    std::string getCurrentPhaseName() const;

    void reset();

private:
    void buildPhasesFromConfig(const IDataNode& config);

    std::unique_ptr<IWorldGenerationStep> createStepFromConfig(const IDataNode& step_config);

    std::unique_ptr<IWorldGenerationPhase> createPhaseFromConfig(const IDataNode& phase_config);
};

} // namespace warfactory