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

#pragma once

#include "glmAbstractBehavior.h"

#include <glmRandomNumberGenerator.h>
#include <glmSmartPointer.h>

namespace glm
{
    class GLM_SDK_API RandomBehaviorOperator : public AbstractBehavior
    {
    private:
        glm::Array<float> _weights;

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

        RandomBehaviorOperator();
        virtual ~RandomBehaviorOperator();

        unsigned int addNext(AbstractBehavior* next, float weight);
        virtual unsigned int addNext(AbstractBehavior* next);
        virtual void removeNext(unsigned int next);
        virtual void clearNexts();

        void setWeight(float weight, unsigned int next);

        inline virtual bool isTimeConsuming() const override;

        virtual void init(BehaviorGraph& graph) override;
        virtual void update(int64_t index, BehaviorGraph& graph, Time dt) override;
        virtual void requestStart(int64_t index, BehaviorGraph& graph) override;
        virtual void requestStop(int64_t index, BehaviorGraph& graph, unsigned int next = _nextInvalidId) 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 RandomBehaviorOperator* create() const override;
    };

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

    //-------------------------------------------------------------------------
    inline RandomBehaviorOperator* RandomBehaviorOperator::create() const
    {
        RandomBehaviorOperator* myNewRandomBehaviorOperator = GLM_NEW(RandomBehaviorOperator, myNewRandomBehaviorOperator, getClassMemoryStatId());
        return myNewRandomBehaviorOperator;
    }

} // namespace glm
