#pragma once

#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>

class ResourcePack;

class ResourceLoader {
   private:
    static std::unique_ptr<ResourceLoader> instance;
    ResourcePack* resource_pack_;
    std::string pack_path_;
    bool fallback_to_files_;

    ResourceLoader();

   public:
    static ResourceLoader& getInstance();
    ~ResourceLoader();

    bool initialize(const std::string& pack_file, bool enable_fallback = true);
    void shutdown();

    std::vector<uint8_t> loadResource(const std::string& filename);
    bool resourceExists(const std::string& filename);

    void setFallbackToFiles(bool enable) { fallback_to_files_ = enable; }
    bool getFallbackToFiles() const { return fallback_to_files_; }

    size_t getLoadedResourceCount() const;
    std::vector<std::string> getAvailableResources() const;

   private:
    static std::vector<uint8_t> loadFromFile(const std::string& filename);
    static std::string getDataPath(const std::string& filename);
};
