//
// Created by sebastian on 07.02.26.
//

#ifndef MAPGENERATOR_H
#define MAPGENERATOR_H
#include <cmath>
#include <random>

#include "HexTile.h"
#include "Map.h"
#include "../../engine/renderer/model/AssetManager.h"
#include "../../engine/toolbox/Random.h"
#include "tileGenerator/ForestTileGenerator.h"

class MapGenerator {
public:
    static void generateHexMap(Map& map, int width, int height, float hexRadius, std::vector<std::shared_ptr<Entity>>& mapEntities) {
        // Zufallsgenerator initialisieren (einmal)
        Random random;

        map.tiles.clear();

        float xOffset = hexRadius * std::sqrt(3.0f);
        float zOffset = hexRadius * 1.5f;

        for (int r = 0; r < height; ++r) {
            for (int q = 0; q < width; ++q) {
                HexTile tile;
                tile.q = q;
                tile.r = r;

                // Pointy-top Hexes
                float x = xOffset * (q + 0.5f * (r % 2));
                float z = zOffset * r;
                tile.worldPos = glm::vec3(x, 0.0f, z);
                tile.radius = hexRadius;

                float randomValue = random.randomFloat(0.0f, 1.0f);
                if (randomValue < 0.5f) {
                    tile.resourceType = RessourceType::WOOD;
                    ForestTileGenerator forestTileGenerator;
                    const std::vector<std::shared_ptr<Entity>> forestEntities = forestTileGenerator.generateHexTile(random, tile.worldPos, mapEntities);
                    tile.entitiesOnTile = forestEntities;
                } else if (randomValue < 0.75f) {
                    tile.resourceType = RessourceType::STONE;
                }
                map.tiles.push_back(tile);
            }
        }
    }

private:

};



#endif //MAPGENERATOR_H
