using System;
using System.Collections.Generic;
using System.Drawing.Text;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using PXP.Crawler.API.Utils;

namespace PXP.Crawler.API.Model.Core
{
    [NodeInfo("Program Output", typeof(ProgramOutput), Category = "Core")]
 
    public class ProgramOutput : Node, IPins
    {
        private List <NodePin> pins = new List<NodePin>();

        public ProgramOutput(Program program) : base(program)
        {
            
        }

        private void UpdatePins()
        {
            if (pins.Count > pinCount)
            {
                while (pins.Count > pinCount)
                {
                    NodePin lp = pins[pins.Count - 1];
                    pins.RemoveAt(pinCount - 1);
                    
                }
            }
            else 
            {
                while (pinCount > pins.Count)
                {
                    NodePin nPin = new NodePin(this);
                    pins.Add(nPin);
                }
            }
        }


        [NodePropertyPins]
        public List<NodePin> Pins
        {
            get
            {
                return pins;
            }
            set
            {
                pins = value;

                pinCount = pins.Count;
            }
        }


        private int pinCount = 0;
        public int PinCount
        {
            get
            {
                return pinCount;
            }
            set
            {
                pinCount = Misc.LimitValue(value, 0, 20);
                UpdatePins();
            }
        }
    }
}
