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

#pragma once

#include <glmSDKAPI.h>
#include <glmAbstractUserBehavior.h>

namespace glm
{
    class PathContext;
    class NavigationData;
	class AbstractGround;
	class CloneFactory;
	class Vector3;
	class BehaviorGraph;

    //-------------------------------------------------------------------------
    // Behavior which allow to Pin character to Mesh
    class GLM_SDK_API SetTerrainBehavior : public AbstractUserBehavior
    {
    private:
        AbstractGround* _ground;
        int _spatialEnvironmentIndex;

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

		SetTerrainBehavior();
        virtual ~SetTerrainBehavior();

        void setTerrainGround(AbstractGround& ground);
        void setSpatialEnvironmentIndex(int spatialEnvironmentIndex);

        // type checking - value derived from this type
        virtual bool isThisType(const AbstractBehavior* value) const override;

    protected:
        // cloning
        friend class glm::CloneFactory;
        inline virtual SetTerrainBehavior* create() const override;

        bool switchLocationSpatialEnv(PathContext& pathContext, int newSpatialEnvIndex, const Vector3& position, NavigationData& navData, const Vector3& upVector, float radius);

        virtual void doInit(BehaviorGraph& graph) override;
        virtual void doFinish(BehaviorGraph& graph) override;
        virtual void doStart(int64_t index, BehaviorGraph& graph) override;
        virtual AbstractBehavior::ResultStatus::Value doStop(int64_t index, BehaviorGraph& graph, Time dt) override;
    };

    //-------------------------------------------------------------------------
    inline SetTerrainBehavior* SetTerrainBehavior::create() const
    {
        SetTerrainBehavior* myNewSetTerrainBehavior = GLM_NEW(SetTerrainBehavior, myNewSetTerrainBehavior, getClassMemoryStatId());
        return myNewSetTerrainBehavior;
    }
} // namespace glm
