#include "WorldGeneration.h"
#include <iostream>
#include <nlohmann/json.hpp>

using json = nlohmann::json;
using namespace warfactory;

#ifdef TESTING
/**
 * @brief Standalone test mode for world-feature module
 */
int main() {
    std::cout << "WorldGeneration Module - Standalone Test Mode" << std::endl;

    try {
        // Create module instance
        WorldGenerationModule worldGeneration;

        // Test basic functionality
        std::cout << "Module type: " << worldGeneration.getType() << std::endl;

        // Test world generation
        json generationResult = worldGeneration.generateWorldMap();
        std::cout << "World generation result: " << generationResult.dump(2) << std::endl;

        // Test coordinate queries
        if (worldGeneration.isGenerated()) {
            std::string terrain = worldGeneration.getTerrainAt(100, 100);
            std::string biome = worldGeneration.getBiomeAt(100, 100);
            float elevation = worldGeneration.getElevationAt(100, 100);

            std::cout << "At (100,100): terrain=" << terrain
                      << ", biome=" << biome
                      << ", elevation=" << elevation << std::endl;
        }

        // Test health status
        json health = worldGeneration.getHealthStatus();
        std::cout << "Health status: " << health.dump(2) << std::endl;

        std::cout << "All tests completed successfully!" << std::endl;

    } catch (const std::exception& e) {
        std::cerr << "Test failed with exception: " << e.what() << std::endl;
        return 1;
    }

    return 0;
}

#else
/**
 * @brief Hot-reload module entry point
 *
 * This function is called by the module loader for hot-reload.
 * It should return a new instance of the module.
 */
extern "C" {
    IModule* createModule() {
        return new WorldGenerationModule();
    }

    void destroyModule(IModule* module) {
        delete module;
    }
}
#endif