#pragma once

#include "map/GMap.h"
#include "warfactory/ASerializable.h"
#include <memory>

namespace warfactory {

/**
 * @brief Container for all world generation data during Phase 1
 *
 * Manages the terrain map and provides high-level world access methods.
 * Designed for hot-reload compatibility with serialization support.
 */
class WorldData : public ASerializable {
private:
    std::unique_ptr<GMap> terrain_map;
    int world_width;
    int world_height;

public:
    WorldData(int width, int height);
    ~WorldData();

    // Prevent copy (expensive with large maps)
    WorldData(const WorldData&) = delete;
    WorldData& operator=(const WorldData&) = delete;

    // Move constructor/assignment for efficiency
    WorldData(WorldData&& other) noexcept;
    WorldData& operator=(WorldData&& other) noexcept;

    // ========================================
    // MAP ACCESS
    // ========================================

    GMap* getTerrainMap();
    const GMap* getTerrainMap() const;

    GTile* getTile(int x, int y);
    const GTile* getTile(int x, int y) const;

    bool isValidCoordinate(int x, int y) const;

    int getWidth() const { return world_width; }
    int getHeight() const { return world_height; }

    // ========================================
    // WORLD STATISTICS
    // ========================================

    float getAverageElevation() const;
    float getAverageTemperature() const;
    int getTotalTileCount() const;

    // ========================================
    // SERIALIZATION
    // ========================================

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

} // namespace warfactory