#ifndef __TILES__TILE_MAP_H__
#define __TILES__TILE_MAP_H__

#include "Chunk.h"
#include <unordered_map>
#include <string>

class TileMap
{
public:
    std::string name;
    int mapWidthInChunks = 0;
    int mapHeightInChunks = 0;
    
    TileMap(const std::string& mapName, int wChunks, int hChunks);
    
    // World coordinates to chunk + local
    Chunk* GetChunk(int worldChunkX, int worldChunkY);
    const Chunk* GetChunk(int worldChunkX, int worldChunkY) const;
    
    Tile* GetTile(int worldTileX, int worldTileY);
    const Tile* GetTile(int worldTileX, int worldTileY) const;

    void SetTile(int worldX, int worldY, const Tile& tile);
    
    // Return only chunks that intersects camera
    std::vector<Chunk*> GetVisibleChunks(int cameraX, int cameraY, int cameraW, int cameraH);
    
    void PrintInfo() const;

private:
    std::unordered_map<uint64_t, Chunk> chunks; // key = (y << 32) | x
    
    uint64_t MakeKey(int cx, int cy) const
    {
        return (static_cast<uint64_t>(cy) << 32 | static_cast<uint32_t>(cx));
    }

};

#endif