//
// Created by m on 12/4/21.
//

#ifndef RLA_IIPP_RESOURCEMANAGER_HPP
#define RLA_IIPP_RESOURCEMANAGER_HPP
#include <unordered_map>
#include "../engine.hpp"

template<typename T, typename K, typename A>
class ResourceManager {
public:
    virtual T fetch_resource(A args) {
        K key = get_key(args);
        if(this->resource_map.find(key) == this->resource_map.end()) {
            T resource = this->load_resource(args);
            this->resource_map[key] = resource;
        }
        return this->resource_map[key];
    }

protected:
    std::unordered_map<K, T> resource_map;
    virtual K get_key(A args)=0;
    virtual T load_resource(A args)=0;
    std::string get_resource_path(std::string path) {
        return fmt::format("{}/{}", RESOURCE_DIR, path);
    }
};


#endif //RLA_IIPP_RESOURCEMANAGER_HPP
