/*********************************************************************
 * \file   AssetHelper.hpp
 *
 * \author Romain BOULLARD
 * \date   April 2026
 *********************************************************************/
#ifndef BIGFOOT_ENGINE_ASSETHELPER_HPP
#define BIGFOOT_ENGINE_ASSETHELPER_HPP
#include <Engine/Asset/AssetContainer.hpp>
#include <Engine/Asset/Reference.hpp>
#include <Engine/Asset/Reference_generated.hpp>

#define ASSET_SOFT_REF_DECL(AssetName, AssetType)                                                                      \
    namespace flatbuffers                                                                                              \
    {                                                                                                                  \
    Flat::Bigfoot::SoftReference PackSoftReference##AssetName(const Bigfoot::SoftReference<AssetType>& p_softRef);     \
    Bigfoot::SoftReference<AssetType> UnPackSoftReference##AssetName(const Flat::Bigfoot::SoftReference& p_softRef);   \
    }

#define ASSET_HARD_REF_DECL(AssetName, AssetType)                                                                      \
    namespace flatbuffers                                                                                              \
    {                                                                                                                  \
    Flat::Bigfoot::HardReference PackHardReference##AssetName(const Bigfoot::HardReference<AssetType>& p_hardRef);     \
    Bigfoot::HardReference<AssetType> UnPackHardReference##AssetName(const Flat::Bigfoot::HardReference& p_hardRef);   \
    }

#define ASSET_CONTAINER(AssetName, AssetType)                                                                          \
    namespace Bigfoot                                                                                                  \
    {                                                                                                                  \
    inline AssetContainer<AssetType> g_##AssetName##Container;                                                         \
    }

#define ASSET_REF_DECL(AssetName, AssetType)                                                                           \
    ASSET_SOFT_REF_DECL(AssetName, AssetType)                                                                          \
    ASSET_HARD_REF_DECL(AssetName, AssetType)

#define ASSET_DECL(AssetName, AssetType)                                                                               \
    ASSET_REF_DECL(AssetName, AssetType)                                                                               \
    ASSET_CONTAINER(AssetName, AssetType)

/****************************************************************************************/

#define ASSET_SOFT_REF_IMPL(AssetName, AssetType)                                                                      \
    namespace flatbuffers                                                                                              \
    {                                                                                                                  \
    Flat::Bigfoot::SoftReference PackSoftReference##AssetName(const Bigfoot::SoftReference<AssetType>& p_softRef)      \
    {                                                                                                                  \
        return {flatbuffers::Pack(p_softRef.GetUUID())};                                                               \
    }                                                                                                                  \
    Bigfoot::SoftReference<AssetType> UnPackSoftReference##AssetName(const Flat::Bigfoot::SoftReference& p_softRef)    \
    {                                                                                                                  \
        return {flatbuffers::UnPack(p_softRef.uuid())};                                                                \
    }                                                                                                                  \
    }

#define ASSET_HARD_REF_IMPL(AssetName, AssetType)                                                                      \
    namespace flatbuffers                                                                                              \
    {                                                                                                                  \
    Flat::Bigfoot::HardReference PackHardReference##AssetName(const Bigfoot::HardReference<AssetType>& p_hardRef)      \
    {                                                                                                                  \
        return {flatbuffers::Pack(p_hardRef.GetUUID())};                                                               \
    }                                                                                                                  \
    Bigfoot::HardReference<AssetType> UnPackHardReference##AssetName(const Flat::Bigfoot::HardReference& p_hardRef)    \
    {                                                                                                                  \
        return {flatbuffers::UnPack(p_hardRef.uuid())};                                                                \
    }                                                                                                                  \
    }

#define ASSET_REF_IMPL(AssetName, AssetType)                                                                           \
    ASSET_SOFT_REF_IMPL(AssetName, AssetType)                                                                          \
    ASSET_HARD_REF_IMPL(AssetName, AssetType)

#define ASSET_IMPL(AssetName, AssetType) ASSET_REF_IMPL(AssetName, AssetType)
#endif
