using System;
using System.Collections;
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.Events
{
    
    public abstract class ChangeNodeBase<T> : Node
    {
        public ChangeNodeBase(Program program) : base(program)
        {
            Name = "Change";
        }

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

        public abstract bool CompareValueChanged(T val);

        protected internal T currValue;

        [NodePropertyPin(NodePinDirection.Input)]
        public T Value
        {
            get
            {
                return currValue;
            }
            set
            {
                if (CompareValueChanged(value))
                {
                    currValue = value;
                    OnChange = true;
                }
            }
        }

        private bool onChange = false;

        [NodePropertyPin(NodePinDirection.Output)]
        public bool OnChange
        {
            get
            {
                return onChange;
            }
            internal set
            {
                if (value)
                {
                    onChange = true;
                    NotifyPropertyChange("OnChange");
                    onChange = false;
                }
            }
        }
    }
}
