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

#pragma once

#include "glmSDKAPI.h"

#include "glmAbstractUserBehavior.h"

#include "glmMutex.h"

namespace glm
{
    class AnimationRole;
    class RagdollEntityComponent_PhysX;

    class GLM_SDK_API DetachBehavior : public AbstractUserBehavior
    {
        friend class RagdollEntityComponent_PhysX;

    public:
        bool _attach;

    private:
        glm::PODArray<unsigned int> _specificBoneIds; /// Input specific bone ids to compute the body ids
        glm::PODArray<int> _rigidBodyIds;             /// Rigid body ids to detach

        glm::SpinLock _initMutex;

        bool _doInitDone;

    public:
        DetachBehavior();
        virtual ~DetachBehavior();

        inline void setRigidBodyIds(const glm::PODArray<unsigned int>& specificBoneIds);

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

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

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

    //-------------------------------------------------------------------------
    inline void DetachBehavior::setRigidBodyIds(const glm::PODArray<unsigned int>& specificBoneIds)
    {
        _specificBoneIds = specificBoneIds;
    }

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