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

#pragma once

#include "glmAbstractBehavior.h"
#include "glmAbstractTrigger.h"

namespace glm
{
    class GLM_SDK_API BlockBehaviorOperator : public AbstractBehavior
    {
    private:
        AbstractTrigger::SP _condition;

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

        BlockBehaviorOperator();
        virtual ~BlockBehaviorOperator();

        void setCondition(const AbstractTrigger::SP& condition);
        inline const AbstractTrigger::SP& getCondition() const;

        inline virtual bool isTimeConsuming() const override;

        virtual void allocate(BehaviorGraph& graph) override;
        virtual void resize(BehaviorGraph& graph) override;
#ifndef NDEBUG
        virtual void init(BehaviorGraph& graph) override;
#endif
        virtual void update(int64_t index, BehaviorGraph& graph, Time dt) override;
        virtual void requestStart(int64_t index, BehaviorGraph& graph) override;

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

    protected:
        // cloning
        friend class CloneFactory;
        virtual void cloneImpl(AbstractBehavior* clone, CloneFactory* factory) const override;
        inline virtual BlockBehaviorOperator* create() const override;
    };

    //-------------------------------------------------------------------------
    inline const AbstractTrigger::SP& BlockBehaviorOperator::getCondition() const
    {
        return _condition;
    }

    //-------------------------------------------------------------------------
    inline bool BlockBehaviorOperator::isTimeConsuming() const
    {
        return false;
    }

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