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

namespace Com.FirmLib.Entity
{
    /// <summary>
    /// 设备信息点定义信息
    /// </summary>
    public class EquipmentInfoPointItem
    {
        public EquipmentInfoPointItem()
        {
            EnumItems = new List<EnumItem>();
        }
        /// <summary>
        /// 
        /// </summary>
        public int ID { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Owner { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Architecture { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Category { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string SubCategory { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string CodeName { get; set; }

        /// <summary>
        ///  单位
        /// </summary>
        public string Unit { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string InputType { get; set; }
        #region 下拉数据源显示

        private string m_EnumSource;
        /// <summary>
        /// 枚举类型数据
        /// </summary>
        public string EnumSource
        {
            get { return m_EnumSource; }
            set
            {
                m_EnumSource = value;
                if (!string.IsNullOrEmpty(m_EnumSource))
                {
                    try
                    {
                        EnumItems = JsonConvert.DeserializeObject<List<EnumItem>>(m_EnumSource);
                    }
                    catch (Exception)
                    {//异常不处理
                    }
                }
            }
        }
        
        public List<EnumItem> EnumItems { get; set; }
        #endregion

        /// <summary>
        /// 
        /// </summary>

        public string Remark { get; set; }

        /// <summary>
        /// 对应的组件编码
        /// </summary>
        public string CollectionCmptCode { get; set; }
        /// <summary>
        /// 是否显示
        /// </summary>
        public bool IsShow { get; set; }

        /// <summary>
        /// 信息点所属类别
        /// </summary>
        public string Classification { get; set; }

        public EquipmentInfoPointItem Clone()
        {
            return this.MemberwiseClone() as EquipmentInfoPointItem;
        }
    }
    /// <summary>
    /// 枚举项信息
    /// </summary>
    public class EnumItem
    {
        [JsonProperty("code")]
        public string Value { get; set; }
        [JsonProperty("name")]
        public string Name { get; set; }

        public override string ToString()
        {
            //绑定前台那里有问题，暂时先这么处理；可能跟前台绑定值Value是object,而项目本身Value是string有关
            return Name??string.Empty;
        }
    }
}
