using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PXP.Crawler.API.Model;
using PXP.Crawler.API.Plugins.Operators;

namespace PXP.Crawler.API.Plugins.Values
{
    public class SwitchNodeBase<T> : ValuesOperatorNodeBase<T>
    {
        private bool toggleState = false;

        public SwitchNodeBase(Program program) : base(program)
        {
            Name = "Switch";
        }

        public override void CreateDesigner()
        {
            base.CreateDesigner();
            designer.Control.BackColor = Color.DarkGreen;
        }

        public override void OnInputPinConnected(string name)
        {
            base.OnInputPinConnected(name);
            Toggle = Toggle;
        }

        protected internal override T ComputeResult()
        {
            Toggle = Toggle;
            return Result;
        }

        [NodePropertyPin(NodePinDirection.Input)]
        public bool Toggle
        {
            get
            {
                return toggleState;
            }
            set
            {
                toggleState = value;
                if (toggleState)
                {
                    Result = value2;
                }
                else
                {
                    Result = value1;
                }
            }
        }
    }
}
