#ifndef KRIMI_DINNER_ENGINE_ASSETMANAGER_H
#define KRIMI_DINNER_ENGINE_ASSETMANAGER_H

/// @file AssetManager.h
/// @brief Access to asset files

#include "Texture.h"
#include "Renderer.h"
#include "Font.h"

#include <map>

// Predefine, because that saves us from including android headers here
struct AAssetManager;

/// @brief Buffer for a loaded asset file
struct FileBuffer
{
    /// Read-only data
    const void* data;

    /// Number of bytes in @ref data
    size_t size;

    /// Internal, don't modify
    void* internal;
};

/// @brief Provides access to asset files
class AssetManager
{
public:
    /// The singleton pointer
    static AssetManager* ptr;

    /// @brief Loads an asset file
    ///
    /// You must free the asset buffer via @ref releaseFileBuffer after you are done with it.
    /// \param path Path to the asset file
    /// \param p_file_buffer Receives the file buffer, if the asset was loaded successfully
    /// \return @c true if the asset was loaded successfully, @c false otherwise
    virtual bool loadFile(const char* path, FileBuffer* p_file_buffer) = 0;

    /// @brief Frees the resources allocated for an asset file
    ///
    /// \param fb The file buffer returned by the load function
    virtual void releaseFileBuffer(FileBuffer& fb) = 0;

    /// @brief Helper for loading a texture
    ///
    /// You should not need this, because the renderer is responsible for loading textures.
    /// \param path Path to the texture file
    /// \param p_texture Receives the texture object
    /// \return @c true if the texture was loaded successfully, @c false otherwise
    bool loadTexture(const char* path, Texture* p_texture);

    bool loadFontData(const char* path, float char_height, FontData* p_font);

    bool loadFontBitmap(const char* path, float char_height, Texture* p_texture);

protected:
    AssetManager() = default;
    virtual ~AssetManager() = default;
    AssetManager(const AssetManager&) = delete;
    AssetManager& operator=(const AssetManager&) = delete;

private:
    // FIXME(Kevin): Temporary workaround
    std::map<std::pair<StringHandle, float>, FontData> m_font_cache;
};

#endif
