#ifndef _H_RESOURCEMANAGER_H
#define _H_RESOURCEMANAGER_H

#include <unordered_map>
#include <memory>
#include <string>

#include "utility/xmlloader.h"
#include "graphics/shader.h"
#include "graphics/sprite.h"
#include <cassert>

class Weapon;
class Script;
class AnimationSet;
class AIScript;
class WeaponScript;
class TileSetData;
class SpriteComponent;

class ResourceManager
{
public:
	ResourceManager() : 
		xmlLoader(std::make_shared<XMLLoader>()) 
	{ 
		xmlLoader->loadWeapons("weapons"); 
		xmlLoader->loadAnimations("animations");
		xmlLoader->loadTileSets("maps/tilesets");
		xmlLoader->loadMaps("maps");
		xmlLoader->loadScenes("scenes"); 
	};

	SpriteAtlas*					loadSpriteAtlas 		(const std::string& path, float frameSize, bool isDirectional = false);
	Sprite*							loadSpriteStatic		(const std::string& path);
	std::shared_ptr<AIScript>		loadAIScript			(const std::string& path);
	std::shared_ptr<WeaponScript>	loadWeaponScript		(const std::string& path);

	const unsigned					loadShader		(const std::string& name, const std::string& vertexPath, const std::string& fragPath);
	std::shared_ptr<Weapon>			loadWeapon		(const std::string& name, const unsigned weaponShaderID, const unsigned bulletShaderID);
	std::shared_ptr<SceneData>		loadScene		(const std::string& id);
	std::shared_ptr<AnimationSet>	loadAnimationSet(const std::string& name, int entityid = 0);
	std::shared_ptr<TileSetData>	loadTileSet		(const std::string& name);

	Shader*					 		getShaderByID(unsigned int ID);

	void clearResources();

	~ResourceManager();

private:
	std::unordered_map<std::string, std::unique_ptr<Shader>>	shaders;
	std::unordered_map<unsigned, Shader*>						shaderIDs;
	std::unordered_map<std::string, std::unique_ptr<Sprite>>	sprites;
	std::unordered_map<std::string, std::shared_ptr<Weapon>>	weapons;
	std::unordered_map<std::string, std::shared_ptr<Script>>	scripts;
	std::unordered_map<std::string, std::shared_ptr<TileSetData>>tileSets;
	//std::unordered_map<std::string, std::shared_ptr<EntityData>> entityData;
	//std::unordered_map<std::string, std::shared_ptr<SceneData>>	 scenes;
	//std::unordered_map<std::string, std::shared_ptr<MapData>>	 maps;
	//std::unordered_map<std::string, std::shared_ptr<TileType>>	 tiles;

	std::shared_ptr<XMLLoader> xmlLoader;
};

#endif // _H_RESOURCEMANAGER_H