#ifndef KRIMI_DINNER_ENGINE_WIN32_ASSET_MANAGER_H
#define KRIMI_DINNER_ENGINE_WIN32_ASSET_MANAGER_H

#include "AssetManager.h"

class Win32AssetManager : public AssetManager
{
public:
    typedef void* FileHandle;

    /// @brief Create the singleton instance
    ///
    /// Sets @ref AssetManager::ptr to the singleton instance
    /// @param asset_root_dir Directory where asset files are located
    static void create(const char* asset_root_dir);

    bool loadFile(const char* path, FileBuffer* p_file_buffer) override;

    void releaseFileBuffer(FileBuffer& fb) override;

    /// @brief Write data to a file.
    /// @param path Path relative to the asset root directory
    /// @param data Data buffer
    /// @param size Number of bytes
    /// @return @c true if writing the file was successfull, @c false otherwise
    bool writeFile(const char* path, const void* data, size_t size);

    /// @brief Write data to a file.
    /// @param path Path relative to the asset root directory
    /// @param file_buffer Data buffer
    /// @return @c true if writing the file was successfull, @c false otherwise
    bool writeFile(const char* path, const FileBuffer& file_buffer);

    /// @brief Creates a file and opens it for writing.
    ///
    /// Overwrites an already existing file.
    /// @param path Path realtive to the asset root directory
    /// @return Handle to the open file, or @c nullptr if the file could not be created.
    FileHandle createFile(const char* path);

    /// @brief Writes data to an open file
    /// @param file File handle
    /// @param data Data buffer
    /// @param size Number of bytes
    /// @return  @c true if writing to the file was successfull, @c false otherwise
    bool writeToFile(FileHandle file, const void* data, size_t size);

    /// @brief Write data to an open file.
    /// @param file File handle
    /// @param file_buffer Data buffer
    /// @return @c true if writing to the file was successfull, @c false otherwise
    bool writeToFile(FileHandle file, const FileBuffer& file_buffer);

    /// @brief Closes an open file.
    /// @param file The file handle
    void closeFile(FileHandle file);

private:
    const char* m_asset_root;
};

#endif
