/***************************************************************************
*                                                                          *
*  Copyright (C) Golaem S.A.  All Rights Reserved.                         *
*                                                                          *
***************************************************************************/

#pragma once

#include "glmCoreAPI.h"
#include "glmRTTI.h"
#include "glmAssetGroupV0.h"
#include "glmMeshAssetV1.h"
#include "glmGeometryAssetV1.h"
#include "glmShadingGroup.h"
#include "glmRenderingType.h"
#include "glmGenericSpecificConverterMappingV6.h"
#include "glmCharacterUserData.h"
#include "glmShaderAssetV1.h"
#include "glmShaderAttributeV0.h"
#include "glmRenderingTypeV3.h"
#include "glmGolaemCharacterInterface.h"

namespace glm
{
    struct GolaemCharacterV4;
    struct GolaemCharacterV5;

    struct GLM_CORE_API GolaemCharacterV6 : public GolaemCharacterInterface
    {
        GLM_VIRTUAL_RTTI("5f5ef6ae-41eb-41b6-bec0-b0186a88faca", glm::GolaemCharacterV6, addAttributes);

    public:
        GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation);

        /// Name of the character
        glm::GlmString _name;

        glm::PODArray<int> _mainAssetGroups;

        glm::Array<AssetGroupV0> _allAssetGroups;
        glm::Array<MeshAssetV1> _meshAssets;

        glm::Array<GeometryAssetV1> _geometryAssets;

        glm::Array<ShadingGroupV1> _shadingGroups;

        glm::Array<ShaderAttributeV0> _shaderAttributes;

        glm::Array<ShaderAssetV1> _shaderAssets;

        glm::Array<RenderingTypeV3> _renderingTypes;

        GenericSpecificConverterMappingV6 _converterMapping; // animation data
        CharacterUserDataV0 _characterUserData;              // additional user data

        GolaemCharacterV6();
        ~GolaemCharacterV6();

        /**
		* \brief V4 backwards compatibility
		* \note no more AssetManager class
		*/
        void createFromV4(GolaemCharacterV4& characterV4);

        /**
		* \brief V5 backwards compatibility
		* \note no more AssetManager class
		*/
        void createFromV5(GolaemCharacterV5& characterV5);

    private:
        GLM_DISALLOW_COPY_AND_ASSIGN(GolaemCharacterV6);
        static void addAttributes();

        // for serialization only
        const GenericSpecificConverterMappingV6& getConverterMapping() const;
        void setConverterMapping(const GenericSpecificConverterMappingV6& mapping);
        const CharacterUserDataV0& getCharacterUserData() const;
        void setCharacterUserData(const CharacterUserDataV0& userData);

        int findAssetGroupIdx(const glm::GlmString& assetGroupName) const;
        int findMeshAssetIdx(const glm::GlmString& meshAssetName) const;
        int findShadingGroupIdx(const glm::GlmString& shadingGroupName) const;
        int findShaderAssetIdx(const glm::GlmString& shaderAssetName) const;

        int findShaderAttributeIdx(const glm::GlmString& shaderAttributeName) const;

        static void getAllMeshAssets(glm::PODArray<int>& meshAssets, const GolaemCharacterV6& character, const AssetGroupV0& assetGroup);
    };
} // namespace glm
