using IRaCIS.Core.Domain.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;

namespace IRaCIS.Core.Domain.Share
{
    /// <summary>
    /// 多环境 配置环境实体
    /// </summary>
    public class ServiceVerifyConfigOption
    {
        public bool OpenUserComplexPassword { get; set; }

        public bool OpenSignDocumentBeforeWork { get; set; }

        public bool OpenTrialRelationDelete { get; set; }

        public bool OpenLoginLimit { get; set; }
    }

    public class SystemEmailSendConfig
    {
        public int Port { get; set; } 

        public string Host { get; set; } 


        public string FromEmail { get; set; }

        public string FromName { get; set; }

        public string AuthorizationCode { get; set; } 
    }


    /// <summary>
    /// 项目基础配置规则
    /// </summary>
    public class AppSettings
    {
        public static string DoctorCodePrefix { get; set; }
        public static string UserCodePrefix { get; set; }


        public static string QCChallengeCodePrefix { get; set; }

        public static string DicomStudyCodePrefix { get; set; }

        public static string NoneDicomStudyCodePrefix { get; set; }

        public static string DefaultInternalOrganizationName { get; set; }

        public static int ImageShareExpireDays { get; set; } = 7;


        public static string SystemSiteCodePrefix { get; set; }

        public static string BlindTaskPrefix  { get; set; }

        /// <summary>
        /// 用户默认密码
        /// </summary>
        public static readonly string DefaultPassword = "123456";


        static AppSettings()
        {
            var configuration = new ConfigurationBuilder()
                .Add(new JsonConfigurationSource
                {
                    Path = "appsettings.json",
                    ReloadOnChange = true
                })            
                .Build();

            DoctorCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DoctorCodePrefix");
            UserCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("UserCodePrefix");
            QCChallengeCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("QCChallengeCodePrefix");
            NoneDicomStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("NoneDicomStudyCodePrefix");
            DicomStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DicomStudyCodePrefix");
            DefaultPassword= configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DefaultPassword");
            SystemSiteCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("SystemSiteCodePrefix");

            DefaultInternalOrganizationName = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("DefaultInternalOrganizationName");

            ImageShareExpireDays = configuration.GetSection("IRaCISBasicConfig").GetValue<int>("ImageShareExpireDays");

            BlindTaskPrefix = configuration.GetSection("IRaCISBasicConfig").GetValue<string>("BlindTaskPrefix");

        }


        //获取实体编码字符串
        public static  string GetCodeStr(int codeInt ,string typeStr)
        {
            switch (typeStr)
            {
                case nameof(Doctor):

                    return DoctorCodePrefix + codeInt.ToString("D4");

                case nameof(User):

                    return UserCodePrefix + codeInt.ToString("D4");

                case nameof(QCChallenge):

                    return QCChallengeCodePrefix+ codeInt.ToString("D5");

                case nameof(NoneDicomStudy):

                    return NoneDicomStudyCodePrefix + codeInt.ToString("D5");

                case nameof(DicomStudy):

                    return DicomStudyCodePrefix + codeInt.ToString("D5");

                case nameof(VisitTask):

                    return "W" + codeInt.ToString("D5");

                case nameof(Site):

                    return SystemSiteCodePrefix + codeInt.ToString("D4");

                default:
                    return string.Empty;
            }
        }

    }

   
}