using FLY.OBJComponents.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;

namespace FLY.Thick.Base.Common
{
    /// <summary>
    /// 异常常量
    /// </summary>
    public class ERRNOs
    {
        public static ERRNOs Instance { get; } = new ERRNOs();

        public ERRNOs() 
        {
            string resourceName = $"dict.StringResource.ERRNO";

            var rd_errnos = (ResourceDictionary)Application.Current.FindResource(resourceName);//异常直接让它出错

            Type t = this.GetType();
            var fields = t.GetFields();

            foreach (var field in fields)
            {
                if (field.Name.StartsWith("ERRNO_"))
                {
                    var errno = (ERRNO)field.GetValue(this);
                    errno.Description = ToDescription(rd_errnos,field.Name);
                    field.SetValue(this, errno);
                }
            }
        }
        string ToDescription(ResourceDictionary rd_errnos, string errNoKey)
        {
            string resourceName = $"str.ERRNO.{errNoKey}";
            return (string)rd_errnos[resourceName];//异常直接让它出错
        }

        public List<ERRNO> GetAll() 
        {
            List<ERRNO> list = new List<ERRNO>();
            Type t = this.GetType();
            var fields = t.GetFields();

            foreach (var field in fields)
            {
                if (field.Name.StartsWith("ERRNO_"))
                {
                    var errno = (ERRNO)field.GetValue(this);
                    list.Add(errno);
                }
            }
            list.Sort((e0, e1) =>
            {
                return e0.Code.CompareTo(e1.Code);
            });

            return list;
        }
        public ERRNO ERRNO_ALARM_TEST = new ERRNO() { Code = 1, Description = "ALARM_TEST" };//"报警测试" };

        public ERRNO ERRNO_AD_MIN = new ERRNO() { Code = 2, Description = "AD_MIN" };//"AD值太小" };

        public ERRNO ERRNO_AD_MAX = new ERRNO() { Code = 3, Description = "AD_MAX" };//"AD值太大" };

        public ERRNO ERRNO_SCRAM = new ERRNO() { Code = 4, Description = "SCRAM" };//"急停" };

        public ERRNO ERRNO_LIMIT = new ERRNO() { Code = 5, Description = "LIMIT" };//"限位" };

        public ERRNO ERRNO_FLYAD7_DC = new ERRNO() { Code = 6, Description = "FLYAD7_DC" };//"AD盒连接断开" };

        public ERRNO ERRNO_WILL_EXP = new ERRNO() { Code = 7, Description = "WILL_EXP" };//"授权将要过期" };

        public ERRNO ERRNO_AUTH_EXP = new ERRNO() { Code = 8, Description = "AUTH_EXP" };//"授权过期" };

        public ERRNO ERRNO_DB_BACKUP = new ERRNO() { Code = 9, Description = "DB_BACKUP" };//"已经连续开机1个月,数据库需要备份归档,请尽快重启服务器" };


        public ERRNO ERRNO_OVERCTRL = new ERRNO() { Code = 11, Description = "OVERCTRL" };//"扫描超控制报警" };

        public ERRNO ERRNO_OVERTOL = new ERRNO() { Code = 12, Description = "OVERTOL" };//"扫描超规格报警" };

        
        public ERRNO ERRNO_SAMPLE_ParamErr = new ERRNO() { Code = 20, Description = "SAMPLE_ParamErr" };//"采样出错:参数异常" };
        public ERRNO ERRNO_SAMPLE_ADZero = new ERRNO() { Code = 21, Description = "SAMPLE_ADZero" };//"采样出错:AD值为0" };
        public ERRNO ERRNO_SAMPLE_NoData = new ERRNO() { Code = 22, Description = "SAMPLE_NoData" };//"采样出错:没有采集数据" };
        public ERRNO ERRNO_SAMPLE_FilterErr = new ERRNO() { Code = 23, Description = "SAMPLE_FilterErr" };//"采样出错:滤波数据与原始数据差异大" };
        public ERRNO ERRNO_SAMPLE_PercentErr = new ERRNO() { Code = 24, Description = "SAMPLE_PercentErr" };//"采样出错:样品AD与上次差异大" };
        public ERRNO ERRNO_SAMPLE_CrossErr = new ERRNO() { Code = 25, Description = "SAMPLE_CrossErr" };//"采样出错:样品比值与上次差异大" };
    
        
    }

}
