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

#pragma once

#include "glmRTTI.h"
#include "glmTypes.h"

#include <glmGolaemCharacterDeclarations.h> // GolaemCharacter declarations

namespace glm
{
    struct ShaderAttributeV2;

    /**
	* \brief Shader Attribure
	*/
    class GLM_CORE_API ShaderAttributeV3
    {
        GLM_RTTI("aaf98808-7356-42d6-aded-5548c8174a7a", ShaderAttributeV3, addAttributes)
    public:
        GLM_CLASS_STAT_ID( glm::MemoryStatIds::GolaemShared);

        /// The name of the attribute
        glm::GlmString _name;

        /// The type of the attribute
        ShaderAttributeType::Value _type = ShaderAttributeType::INT;

        /// The string value
        glm::GlmString _stringValue;

        /// If true, a random value between the min and max values will be used,
        /// otherwise the PP attribute value will be used instead
        ShaderAttributeValueType::Value _valueType = ShaderAttributeValueType::RANDOM;

        /// The PP attribute from which to retrieve the value
        glm::GlmString _ppAttr;

        // added in v8.0.0
        glm::PODArray<float> _weights;

        // added in v8.2.2
        glm::PODArray<float> _values;

    protected:
        /// The min value (to be interpreted according to the type)
        glm::GlmString _minValue = "0";

        /// The max value (to be interpreted according to the type)
        glm::GlmString _maxValue = "0";

        int _minIntValueCached;
        float _minFloatValueCached;
        Vector3 _minVectorValueCached;

        int _maxIntValueCached;
        float _maxFloatValueCached;
        Vector3 _maxVectorValueCached;

    public:
        /**
         * \brief V2 backwards compatibility
         * \note V2 does not have values
         */
        void createFromV2(const ShaderAttributeV2& shaderAttributeV2);

        void setMinValue(glm::GlmString minValue);
        void setMaxValue(glm::GlmString maxValue);

        inline glm::GlmString getMinValue() const; // for inspection
        inline glm::GlmString getMaxValue() const; // for inspection

        inline const int& getMinIntValue() const;
        inline const float& getMinFloatValue() const;
        inline const Vector3& getMinVectorValue() const;

        inline const int& getMaxIntValue() const;
        inline const float& getMaxFloatValue() const;
        inline const Vector3& getMaxVectorValue() const;

    protected:
        /**
		* \brief Inspection needed method declaring the inspectable attributes.
		*/
        static void addAttributes();

        /**
		* \brief Accessor to the attribute type needed for inspection
		*/
        int getTypeAsInt() const;
        void setTypeFromInt(int value);

        /**
		* \brief Accessor to the attribute type needed for inspection
		*/
        int getValueTypeAsInt() const;
        void setValueTypeFromInt(int value);
    };

    //------------------------------------------------------------
    inline glm::GlmString ShaderAttributeV3::getMinValue() const
    {
        return _minValue;
    }

    //------------------------------------------------------------
    inline glm::GlmString ShaderAttributeV3::getMaxValue() const
    {
        return _maxValue;
    }

    //------------------------------------------------------------
    inline const int& ShaderAttributeV3::getMinIntValue() const
    {
        return _minIntValueCached;
    }

    //------------------------------------------------------------
    inline const float& ShaderAttributeV3::getMinFloatValue() const
    {
        return _minFloatValueCached;
    }

    //------------------------------------------------------------
    inline const Vector3& ShaderAttributeV3::getMinVectorValue() const
    {
        return _minVectorValueCached;
    }

    //------------------------------------------------------------
    inline const int& ShaderAttributeV3::getMaxIntValue() const
    {
        return _maxIntValueCached;
    }

    //------------------------------------------------------------
    inline const float& ShaderAttributeV3::getMaxFloatValue() const
    {
        return _maxFloatValueCached;
    }

    //------------------------------------------------------------
    inline const Vector3& ShaderAttributeV3::getMaxVectorValue() const
    {
        return _maxVectorValueCached;
    }
} // namespace glm
