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

namespace MECF.Framework.UI.Client.TrayThickness
{
    public class CoatingData : ICloneable
    {
        /// <summary>
        /// 存储Tray的ID
        /// </summary>
        public string GUID { get; set; } = "0";
        /// <summary>
        /// 界面上标签显示
        /// </summary>
        public string Caption { get; set; }
        /// <summary>
        /// Tray环名称
        /// </summary>
        public string SerialNumber { get; set; }
        /// <summary>
        /// 设置或返回当前托盘组件所属的PM腔名称。
        /// </summary>
        public string PmOwned { get; set; }
        /// <summary>
        /// 厚度最大值
        /// </summary>
        public string MAX { get; set; }
        /// <summary>
        /// 当前厚度
        /// </summary>
        public string Current { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public string CreatTime { get; set; }

        public string Index { get; set; } = "0";

        public CoatingData()
        {

            CreatTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        public CoatingData(string caption, string uid) : this()
        {
            Caption = caption;
            GUID = uid;
        }

        public bool Validate(out string reason)
        {
            reason = string.Empty;
            if (string.IsNullOrEmpty(SerialNumber))
                reason = "Serial SerialNumber can not be empty";

            if(string.IsNullOrEmpty(PmOwned))
                reason = "PM name can not be empty";

            // reformat reason
            if (!string.IsNullOrEmpty(reason))
                reason = $"{Caption} {reason}";

            return string.IsNullOrEmpty(reason);
        }

        public object Clone()
        {
            return new CoatingData()
            {
                SerialNumber = SerialNumber,
                PmOwned = PmOwned,
                MAX = MAX,
                Current = Current
            };
        }

        public void Update(CoatingData newData)
        {
            SerialNumber = newData.SerialNumber;
            PmOwned = newData.PmOwned;
            MAX = newData.MAX;
            Current = newData.Current;
        }
    }
}
