#ifndef RESOURCEPACK_H
#define RESOURCEPACK_H

#include <SparrowSerializer/serializable.h>

class Texture;
class PBRMaterial;

/**
 * @brief The ResourceInterface struct holds a resource, it handles its loading and its destruction
 */
struct ResourceInterface : public Serializable
{
    P_STRING(m_name)

    virtual void load(float & progress) = 0;

    virtual void destroy() = 0;

    virtual void gui() {}
};

/**
 * @brief The ResourcePack class is just a container of LoadTask, it only exists for serialization purposes
 */
struct ResourcePack : public Serializable
{
    P_STRING(m_name)
    P_VECTOR_REFERENCE(ResourceInterface, m_resources)

    ResourcePack() {}

    void gui();

    SERIALIZABLE(ResourcePack, CAST(m_name), CAST(m_resources))
};

//
// Some LoadTask implementations
//

class TextureResource : public ResourceInterface
{
    P_STRING(m_path)
    P_INT(m_bitsPerPixel)
    P_BOOL(m_isVerticallyReversed)
    P_BOOL(m_needsMipMaps)

    Texture* m_texture;

public:
    TextureResource();
    virtual ~TextureResource();

    SERIALIZABLE(TextureResource, CAST(m_name), CAST(m_path), CAST(m_bitsPerPixel), CAST(m_isVerticallyReversed), CAST(m_needsMipMaps))

    void load(float & progress);

    void destroy();

    void gui();
};

class MaterialResource : public ResourceInterface
{
    P_VEC3(m_albedo)
    P_FLOAT(m_metallic)
    P_FLOAT(m_roughness)
    P_VEC3(m_emission)
    P_FLOAT(m_opacity)
    P_STRING(m_albedoTexture)
    P_STRING(m_metallicTexture)
    P_STRING(m_roughnessTexture)
    P_STRING(m_emissionTexture)
    P_STRING(m_normalTexture)
    P_STRING(m_alphaMaskTexture)

    PBRMaterial* m_material;

public:
    MaterialResource();
    virtual ~MaterialResource();

    SERIALIZABLE(MaterialResource,
        CAST(m_name),
        CAST(m_albedo),
        CAST(m_metallic),
        CAST(m_roughness),
        CAST(m_emission),
        CAST(m_opacity),
        CAST(m_albedoTexture),
        CAST(m_metallicTexture),
        CAST(m_roughnessTexture),
        CAST(m_emissionTexture),
        CAST(m_normalTexture),
        CAST(m_alphaMaskTexture))

    void load(float & progress);

    void destroy();

    void gui();
};

#endif // RESOURCEPACK_H
