using IRaCIS.Core.Domain.Share;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
namespace IRaCIS.Core.Infra.EFCore.Common
{
    public static class ReadingCommon
    {
        /// 
        /// 标准字典设置
        /// 
        public static class CriterionDictionary
        {
            /// 
            /// 全局评估类型
            /// 
            public const string GlobalAssess = "GlobalAssessType";
            /// 
            /// 肿瘤学评估类型
            /// 
            public const string OncologyAssess = "OncologyAssessType";
            ///// 
            ///// 标准字典需要配置的相
            ///// 
            //public static  List CriterionDictionaryCodeList = new List()
            //{
            //    "LesionType",
            //    "QuestionType"
            //}; 
        }
        /// 
        /// 获取DictionaryGroup
        /// 
        public static List GetCrterionDictionaryGroup(bool isConvertedTask)
        {
            if (isConvertedTask)
            {
                return new List() { CrterionDictionaryGroup.General, CrterionDictionaryGroup.Converted };
            }
            else
            {
                return new List() { CrterionDictionaryGroup.General, CrterionDictionaryGroup.BeforeConvert };
            }
        }
        /// 
        /// 枚举数组转字符串数组 方法名简短
        /// 
        /// 
        /// 
        /// 
        public static List EnumToString(List emus) where T : Enum
        {
            return emus.Select(x => ((int)(object)x).ToString()).ToList();
        }
        /// 
        /// 获取语言名称
        /// 
        /// 
        /// 
        /// 
        /// 
        public static string LanguageName(this string Name, string englishName, bool isEN)
        {
            return isEN ? englishName : Name;
        }
        /// 
        /// 阅片问题类型
        /// 
        public static class QuestionType
        {
            /// 
            /// 类型自动计算
            /// 
            public const string Calculation = "calculation";
        }
        public static Dictionary SplitLesionDic = new Dictionary()
        {
             {1, "a"  },
             {2, "b"  },
             {3, "c"  },
             {4, "d"  },
             {5, "e"  },
             {6, "f"  },
             {7, "g"  },
             {8, "h"  },
             {9, "i"  },
             {10, "j"  },
             {11, "k"  },
             {12, "l"  },
             {13, "m"  },
             {14, "n"  },
             {15, "o"  },
             {16, "p"  },
             {17, "q"  },
             {18, "r"  },
             {19, "s"  },
             {20, "t"  },
             {21, "u"  },
             {22, "v"  },
             {23, "w"  },
             {24, "x"  },
             {25, "y"  },
             {26, "z"  },
        };
        public static string GetLesionMark(this decimal value)
        {
            if (value % 1 == 0)
            {
                return decimal.ToInt32(value).ToString().PadLeft(2, '0');
            }
            else
            {
                return Math.Floor(value).ToString().PadLeft(2, '0') + SplitLesionDic[decimal.ToInt32((value % 1) * 100)];
            }
        }
        public static Dictionary TaskNumDic = new Dictionary()
        {
            {ReadingCategory.Visit, 0  },
            {ReadingCategory.Global,(decimal) 0.03  },
            {ReadingCategory.Judge,(decimal) 0.02  },
            {ReadingCategory.Oncology, (decimal)0.06  },
        };
        public const string EvaluationReason = "肿瘤学阅片评估原因请依据临床数据填写,在与影像学结果不一致时必填。";
        /// 
        /// 获取枚举Int值
        /// 
        /// 
        /// 
        /// 
        public static string GetEnumNullInt(this T? value) where T : struct, Enum
        {
            if (value == null)
            {
                return string.Empty;
            }
            else
            {
                return ((int)(object)value).ToString();
            }
        }
        /// 
        /// 获取枚举Int值
        /// 
        /// 
        /// 
        /// 
        public static string GetEnumInt(this T value) where T : Enum
        {
            return ((int)(object)value).ToString();
        }
        /// 
        /// 字符匹配枚举
        /// 
        /// 
        /// 
        /// 
        /// 
        public static bool EqEnum(this string value, T enumValue) where T : Enum
        {
            try
            {
                return int.Parse(value) == (int)(object)enumValue;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public static decimal NullChange0(this decimal? value)
        {
            if (value == null)
            {
                return 0;
            }
            else
            {
                return value.Value;
            }
        }
        public static decimal? IsNullOrEmptyReturnNull(this string value)
        {
            try
            {
                if (value == null || value == string.Empty || value == "NA")
                {
                   return null;
                }
                else
                {
                    return decimal.Parse(value);
                }
            }
            catch (Exception)
            {
                return null;
            }
        }
        public static decimal IsNullOrEmptyReturn0(this string value)
        {
            try
            {
                if (value == null || value == string.Empty || value == "NA")
                {
                    return 0;
                }
                else
                {
                    return decimal.Parse(value);
                }
            }
            catch (Exception)
            {
                return 0;
            }
        }
        /// 
        /// 获取DisplayName
        /// 
        /// 
        /// 
        public static string GetDisplayName(this Enum enumName)
        {
            var type = enumName.GetType();//先获取这个枚举的类型
            var field = type.GetField(enumName.ToString());//通过这个类型获取到值
            var obj = (DisplayAttribute)field.GetCustomAttribute(typeof(DisplayAttribute));//得到特性
            return obj.Name ?? "";
        }
    }
}