using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using PXP.Crawler.API.Designers.Property;
using PXP.Crawler.API.Model;

namespace PXP.Crawler.API.Model.Core {

    [NodeInfo("Program", typeof(ProgramNode), Category = "Core", 
        Description = "Provide programs with input and control...")]
    public class ProgramNode : Node
    {
        internal int programID = -1;
        internal string programName = "";

        internal Program myProgram;

        public ProgramNode(Model.Program program) : base(program)
        {
            program.project.programs.Changed += programs_Changed;
        }

        void programs_Changed(object sender, EventArgs e)
        {
            ProgramID = ProgramID;}

        [Editor(typeof(ProgramIDPropertyEditor), typeof(UITypeEditor))]
        [NodeSerializeProperty]
        public int ProgramID
        {
            get
            {
                return programID;
            }
            set
            {
                programID = value;
                myProgram = program.project.FindProgramByID(programID);
            }
        }

        [NodePropertyPin(NodePinDirection.Output)]
        public string ProgramName
        {
            get
            {
                if (myProgram != null)
                {
                    return myProgram.Name;
                }
                else
                {
                    return "";}
            }
            private set
            {
                programName = value;
                if (programName.Length > 0)
                {
                    Name = "Program (" + programName + ")";
                }
            }
        }
    }
}
