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

namespace PXP.Crawler.API.Plugins.Operators
{
    public class CompareValuesNodeBase<T> : Node
    {
        public CompareValuesNodeBase(Program program) : base(program)
        {
        }

        protected internal bool valuesSet = false;
        protected internal bool isEqual = false;

        protected internal T value1;
        protected internal T value2;

        protected virtual internal bool CompareValues()
        {
            return false;
        }

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

        public override void OnInputPinConnected(string name)
        {
            base.OnInputPinConnected(name);
            valuesSet = value1 != null && value2 != null;
            if (!valuesSet)
                IsEqual = false;
        }

        public override void OnInputPinDisconnected(string name)
        {
            base.OnInputPinDisconnected(name);            
            valuesSet = false;
            isEqual = false;
        }

        [NodePin(NodePin.NodePinDirection.Input)]
        public T Value1
        {
            get
            {
                return value1;
            }
            set
            {
                value1 = value;
                valuesSet = value1 != null;
                if (valuesSet)
                    IsEqual = CompareValues();
            }
        }

        [NodePin(NodePin.NodePinDirection.Input)]
        public T Value2
        {
            get
            {
                return value2;
            }
            set
            {
                value2 = value;
                valuesSet = value2 != null;
                if (valuesSet)
                    IsEqual = CompareValues();
            }
        }

        [NodePin(NodePin.NodePinDirection.Output)]
        public bool IsEqual
        {
            get
            {
                return isEqual;
            }
            internal set
            {
                isEqual = value;
                NotifyPropertyChange("IsEqual");
            }
        }
    }
}
