#pragma once

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

class ResourcePack;

class ResourceLoader {
   public:
    static auto getInstance() -> ResourceLoader&;
    ~ResourceLoader();

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

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

    void setFallbackToFiles(bool enable) { fallback_to_files_ = enable; }
    [[nodiscard]] auto getFallbackToFiles() const -> bool { return fallback_to_files_; }

    [[nodiscard]] auto getLoadedResourceCount() const -> size_t;
    [[nodiscard]] auto getAvailableResources() const -> std::vector<std::string>;

   private:
    ResourceLoader();  // Constructor privado (singleton)

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

    static std::unique_ptr<ResourceLoader> instance;
    ResourcePack* resource_pack_{nullptr};
    std::string pack_path_;
    bool fallback_to_files_{true};
};
