#pragma once
#include <array>
#include <map>
#include <vector>

#include "structs.h"

class GroundTileType;
static const int WORLD_WIDTH = 34;
static const int WORLD_HEIGHT = 34;

static const int TILE_WIDTH = 50;
static const int TILE_HEIGHT = 50;

class WorldTile;

enum TileDirection {
	TopLeft,
	TopMiddle,
	TopRight,

	MiddleLeft,
	//me
	MiddleRight,

	BottomLeft,
	BottomMiddle,
	BottomRight
};

struct surroundingTiles {

	std::vector<WorldTile *> m_tiles { 8, nullptr };

	void SetTile(TileDirection direction, WorldTile* tile) {
		m_tiles[static_cast<int>(direction)] = tile;
	}

	WorldTile * GetTile(TileDirection direction) {
		return m_tiles[static_cast<int>(direction)];
	}
};

class WorldGridManager {
public:
	WorldGridManager();
	~WorldGridManager();
	surroundingTiles GetSurroundingTiles(const WorldTile* world_tile);
	static Vector2f GetIndexFromPosition(Vector2f position);

	WorldGridManager(const WorldGridManager& other) = delete;
	WorldGridManager(WorldGridManager&& other) = default;
	WorldGridManager& operator=(const WorldGridManager& other) = delete;
	WorldGridManager& operator=(WorldGridManager&& other) = delete;
	

	WorldTile * GetTileAtIndex(const int x, const int y) const;
	WorldTile * GetTileAtWorldPos(const Vector2f& pos) const;

	void SetTileAtIndex(const int x, const int y, WorldTile* tile);

private:
	std::array<std::array<WorldTile *, WORLD_WIDTH>, WORLD_HEIGHT> m_worldTiles;
};
