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

#pragma once

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

namespace glm
{
    class GLM_SDK_API AlternativeBehaviorOperator : public AbstractBehavior
    {
    private:
        glm::Array<AbstractTrigger::SP> _conditions;

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

        AlternativeBehaviorOperator();
        virtual ~AlternativeBehaviorOperator();

        unsigned int addNext(AbstractBehavior* next, const AbstractTrigger::SP& condition);
        virtual unsigned int addNext(AbstractBehavior* next);
        virtual void removeNext(unsigned int next);
        virtual void clearNexts();

        void setCondition(const AbstractTrigger::SP& condition, unsigned int next);

        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 AlternativeBehaviorOperator* create() const override;
    };

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

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