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

namespace Agv
{
    public class Node
    {
        /// <summary>
        /// 节点名称
        /// </summary>
        public string Name { set; get; } = "";
        /// <summary>
        /// 料架号
        /// </summary>
        public string RFID { set; get; } = "";
        /// <summary>
        /// 标记
        /// </summary>
        public string Mark { set; get; } = "";
        /// <summary>
        /// 动作
        /// </summary>
        public ClientAction Action { set; get; } = ClientAction.None;
        /// <summary>
        /// 优先级
        /// </summary>
        public ClientLevel Level { set; get; } = ClientLevel.Low;
        /// <summary>
        /// 客户端类型
        /// </summary>
        public ClientType Type { set; get; } = ClientType.None;
        /// <summary>
        /// 料架类型
        /// </summary>
        public ClientShelf Shelf { set; get; } = ClientShelf.None;

        public Node(string name,string rfid="",string mark="",ClientAction action = ClientAction.None,
            ClientLevel level = ClientLevel.Low,ClientShelf shelfType = ClientShelf.None,ClientType clientType = ClientType.None)
        {
            Name = name;
            RFID = rfid;
            Mark = mark;
            Action = action;
            Level = level;
            Type = clientType;
            Shelf = shelfType;
        }
        public Node(string name, string rfid = "", ClientAction action = ClientAction.None)
        {
            Name = name;
            RFID = rfid;
            Action = action;
        }

        public Node(string name)
        {
            Name = name;
        }

        public Node() { }
        /// <summary>
        /// 所有属性的文本形式
        /// </summary>
        /// <returns></returns>
        public string ToText()
        {
            System.Reflection.PropertyInfo[] info = this.GetType().GetProperties();
            string[] arr = new string[info.Length];
            for (int i = 0; i < info.Length; i++)
                arr[i] = info[i].Name + "=" + info[i].GetValue(this).ToString();
            return string.Join(",", arr);
        }
        public override bool Equals(object obj)
        {
            if (obj is Node)
            {
                Node node = (Node)obj;
                if (Name.Equals(node.Name) && RFID.Equals(node.RFID) && Mark.Equals(node.Mark) &&
                    Action.Equals(node.Action) && Level.Equals(node.Level) && Type.Equals(node.Type) &&
                    Shelf.Equals(node.Shelf))
                    return true;
                else
                    return false;
            }
            return false;
        }
        /// <summary>
        /// 拷贝一个新的实例
        /// </summary>
        /// <returns></returns>
        public Node ToCopy()
        {
            Node node = new Node();
            System.Reflection.PropertyInfo[] info1 = node.GetType().GetProperties();
            System.Reflection.PropertyInfo[] info2 = this.GetType().GetProperties();
            for (int i = 0; i < info1.Length; i++)
                info1[i].SetValue(node, info2[i].GetValue(this));
            return node;

        }
    }
}