using DeviceRepair.Models.Enum;
using DeviceRepair.Models.OperationHistory;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace DeviceRepair.Models.Attr
{
    [Serializable]
    [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)]
    [ComVisible(true)]
    public sealed class HistoryFilterFieldAttribute : Attribute
    {
        #region Fields

        /// <summary>
        /// 编码
        /// </summary>
        private string _Code;
        /// <summary>
        /// 文本描述
        /// </summary>
        private string _Description;
        /// <summary>
        /// 默认值
        /// </summary>
        private string _DefaultValue;
        /// <summary>
        /// 控件类型
        /// </summary>
        private HistoryFilterCtlType _CtlType;
        /// <summary>
        /// 展示顺序
        /// </summary>
        private int _ColumnSequence;
        /// <summary>
        /// 是否模糊匹配
        /// </summary>
        private bool _Fuzzy;

        #endregion


        #region Ctor
        /// <summary>
        /// Ctor
        /// </summary>
        public HistoryFilterFieldAttribute()
        {
        }
        /// <summary>
        /// Ctor
        /// </summary>
        public HistoryFilterFieldAttribute(string _code, string _Desc)
        {
            _Code = _code;
            _Description = _Desc;
        }
        #endregion

        #region Property
        /// <summary>
        /// 编码
        /// </summary>
        public string Code
        {
            get { return _Code; }
            set { _Code = value; }
        }
        /// <summary>
        /// 文本描述
        /// </summary>
        public string Description
        {
            get { return _Description; }
            set { _Description = value; }
        }
        /// <summary>
        /// 默认值
        /// </summary>
        public string DefaultValue
        {
            get { return _DefaultValue; }
            set { _DefaultValue = value; }
        }
        /// <summary>
        /// 控件类型
        /// </summary>
        public HistoryFilterCtlType CtlType
        {
            get { return _CtlType; }
            set { _CtlType = value; }
        }

        //列展示顺序【预留】
        public int ShowSequence
        {
            get { return _ColumnSequence; }
            set { _ColumnSequence = value; }
        }
        //是否模糊匹配
        public bool Fuzzy
        {
            get { return _Fuzzy; }
            set { _Fuzzy = value; }
        }

        #region 用在界面上不显示，但是默认执行的查询条件参数字段
        private string m_DefaultNotShowQueryParamValue = string.Empty;

        /// <summary>
        /// 用在界面上不显示，但是默认执行的查询条件参数字段
        /// </summary>
        public string DefaultNotShowQueryParamValue
        {
            get { return m_DefaultNotShowQueryParamValue; }
            set { m_DefaultNotShowQueryParamValue = value; }
        }
        #endregion

        // "I:登陆;O:登出"
        public string QueryItems
        {
            get;
            set;
        }

        public IList<ComboBoxValueStruct> QueryItemDisplayList
        {
            get
            {
                IList<ComboBoxValueStruct> vStruct = new List<ComboBoxValueStruct>();
                if (string.IsNullOrEmpty(QueryItems))
                {
                    return null;
                }

                var vDicCounts = QueryItems.Split(';');
                foreach (var item in vDicCounts)
                {
                    var vValueGroups = item.Split(':');
                    if (vValueGroups.Length != 2)
                    {
                        throw new ArgumentException("查询条件复选框预制值格式设置有误！");
                    }
                    vStruct.Add(new ComboBoxValueStruct() { Value = vValueGroups[0].Trim(), Display = vValueGroups[1].Trim() });
                }
                return vStruct;
            }
        }

        #endregion
    }
}
