#pragma once

#include <SDL3/SDL.h>

#include <cstdint>
#include <string>
#include <unordered_map>
#include <vector>

class Menu;
class Text;
class Texture;
struct JA_Music_t;
struct JA_Sound_t;

// Precarga y posee todos los recursos del juego durante toda la vida de la app.
// Singleton inicializado desde Director; las escenas consultan handles via get*().
class Resource {
   public:
    static void init(SDL_Renderer *renderer);
    static void destroy();
    static Resource *get();

    Texture *getTexture(const std::string &name);
    JA_Sound_t *getSound(const std::string &name);
    JA_Music_t *getMusic(const std::string &name);
    std::vector<std::string> &getAnimationLines(const std::string &name);
    Text *getText(const std::string &name);  // name sin extensión: "smb2", "nokia2", ...
    Menu *getMenu(const std::string &name);  // name sin extensión: "title", "options", ...
    const std::vector<uint8_t> &getDemoBytes() const { return demoBytes_; }

   private:
    explicit Resource(SDL_Renderer *renderer);
    ~Resource();

    void preloadAll();

    SDL_Renderer *renderer_;

    std::unordered_map<std::string, Texture *> textures_;
    std::unordered_map<std::string, JA_Sound_t *> sounds_;
    std::unordered_map<std::string, JA_Music_t *> musics_;
    std::unordered_map<std::string, std::vector<std::string>> animationLines_;
    std::unordered_map<std::string, Text *> texts_;
    std::unordered_map<std::string, Menu *> menus_;
    std::vector<uint8_t> demoBytes_;

    static Resource *instance_;
};
