#pragma once
#include "../defs.h"

#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <filesystem>
#include <span>
#include <string>
#include <unordered_map>

namespace quokka_gfx
{
class Application;
//------------------------------------------------------------
class AssetManager
{
  public:
  AssetManager()                                   = delete;      // Default constructor
  virtual ~AssetManager()                          = default;     // Default destructor
  AssetManager(const AssetManager &obj)            = delete;      // Copy constructor
  AssetManager(AssetManager &&obj)                 = delete;      // Move constructor
  AssetManager &operator=(const AssetManager &obj) = delete;      // Copy assignment operator
  AssetManager &operator=(AssetManager &&obj)      = delete;      // Move assignment operator

  explicit AssetManager(SDL_Renderer *renderer);     // Constructor
  void clear();                                      // Clear all loaded assets

  // Texture management
  bool loadTexture(const HashID &id, const std::filesystem::path &filePath);     // Load a texture from a file path
  bool loadTexture(const HashID &id, const std::span<const uint8_t> &buffer);                                 // Load a texture from a memory buffer
  [[nodiscard]] SDL_Texture *getTexture(const HashID &id) const;                                       // Get a texture by its ID
  void                       unloadTexture(const HashID &id);                                          // Unload a texture by its ID

  // Font management
  TTF_Font               *loadFont(const HashID &id, const std::filesystem::path &filePath, int fontSize);
  [[nodiscard]] TTF_Font *getFont(const HashID &id) const;
  void                    unloadFont(const HashID &id);

  protected:
  SDL_Renderer *m_renderer = nullptr;

  std::unordered_map<HashID, Texture> m_textures;
  std::unordered_map<HashID, Font>    m_fonts;
};
//------------------------------------------------------------
}     // namespace quokka_gfx
