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

#pragma once

#include "glmSDKAPI.h"
#include <glmAbstractTrigger.h>

namespace glm
{
    class GLM_SDK_API LogicalOperatorTrigger : public AbstractTrigger
    {
    public:
        unsigned int _operatorType;
		glm::Array<AbstractTrigger::SP> _triggers;

        typedef SmartPointer<LogicalOperatorTrigger> SP;

        GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation);

        struct LogicalOperator
        {
        public:
            enum Value
            {
                AND,
                OR,
                XOR,
                NOT,
                END
            };
        };

        LogicalOperatorTrigger(LogicalOperator::Value operatorType = LogicalOperator::AND);
		LogicalOperatorTrigger(LogicalOperator::Value operatorType, AbstractTrigger::SP trigger0);
		LogicalOperatorTrigger(LogicalOperator::Value operatorType, AbstractTrigger::SP trigger0, AbstractTrigger::SP trigger1);
        virtual ~LogicalOperatorTrigger();

        virtual void allocate(BehaviorGraph& behaviorGraph) override;
        virtual void resize(BehaviorGraph& behaviorGraph) override;
		virtual bool isShareable() override;

    protected:
        virtual bool doCall(int64_t index, AbstractBehavior* behavior, BehaviorGraph& behaviorGraph, bool isAttached) override;
        virtual void doReset(int64_t index, AbstractBehavior* behavior, BehaviorGraph& behaviorGraph) override;

        // cloning
        friend class CloneFactory;
        virtual void cloneImpl(AbstractTrigger* clone, CloneFactory* factory) const override;
        inline virtual LogicalOperatorTrigger* create() const override;
    };

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

} // namespace glm
