using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace PXP.Crawler.API.Model
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public class NodeSerializeProperty : Attribute
    {
    }


    [Flags]
    public enum NodePinDirection
    {
        Auto,
        Input,
        Output
    }

    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public class NodePropertyPin : Attribute
    {

        internal bool isBang;

        public NodePropertyPin(NodePinDirection direction = NodePinDirection.Auto, bool bang = false)
        {
            this.direction = direction;
            this.isBang = bang;
        }

        internal NodePinDirection direction;
    }

    [AttributeUsage(AttributeTargets.Property)]
    public class NodePropertyPins : Attribute
    {
        public NodePropertyPins()
        {
            
        }
    }


    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class NodeInfo : Attribute
    {

        [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
        public class NodeInfoIcon : Attribute
        {
            internal Type resType;
            internal string resName;
            internal bool hasNodeImage;
            internal Image nodeImage;

            public NodeInfoIcon(Type resourcesType, string resourceName)
            {
                resType = resourcesType;
                resName = resourceName;
            }

            internal void Load()
            {
                PropertyInfo imPropInfo = resType.GetProperty(resName);
                if (imPropInfo != null)
                {
                    object nodeImageObj = imPropInfo.GetValue(null);
                    if (nodeImageObj is Bitmap)
                    {
                        nodeImage = (Bitmap)nodeImageObj;
                        hasNodeImage = true;
                    }
                }
                if (!hasNodeImage)
                {
                    nodeImage = Properties.Resources.DefaultNode;
                    hasNodeImage = true;
                }
            }

            public string ImageName
            {
                get
                {
                    return resType.FullName + "." + resName;
                }
            }

            public Image Image
            {
                get { return nodeImage; }
            }

        }

        internal string name = "";
        internal NodeInfoIcon icon = null;
        internal Type nodeType = null;

        internal Size defaultSize = new Size(150, 50);
        internal bool lockSize = false;
        internal bool lockWidth = false;
        internal bool lockHeight = false;

        public NodeInfo(string Name, Type nodeType = null)
        {
            name = Name;
            Category = "";
            Description = "";
            this.nodeType = nodeType;
        }

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        public bool LockSize
        {
            get { return lockSize; }
            set { lockSize = value; }
        }

        public bool LockWidth
        {
            get { return lockWidth; }
            set { lockWidth = value; }
        }

        public bool LockHeight
        {
            get { return lockHeight; }
            set { lockHeight = value; }
        }

        public int DefaultWidth
        {
            get
            {
                return defaultSize.Width;
            }
            set
            {
                defaultSize.Width = value;
            }
        }

        public int DefaultHeight
        {
            get
            {
                return defaultSize.Height;
            }
            set
            {
                defaultSize.Height = value;
            }
        }

        public string Category { get; set; }

        public string Description { get; set; }

        public NodeInfoIcon Icon
        {
            get { return icon; }
        }

        public Type NodeType
        {
            get { return nodeType; }
        }
    }
}
