using SqlSugar;

namespace ServiceCenter
{
    /// <summary>
    ///  服务中心
    /// </summary>
    public static class ServiceHub
    {
        #region 配置中心

        /// <summary>
        /// 数据库连接字符串集合
        /// </summary>
        public static List<DataBaseConnectionString>? DbConnectionStrings { get; set; } = null!;

        /// <summary>
        /// Redis连接字符串集合
        /// </summary>
        public static List<DataBaseConnectionString>? RedisConnectionStrings { get; set; } = null!;

        /// <summary>
        /// 设备IP集合
        /// </summary>
        public static List<string> DeviceIPList { get; set; } = null!;

        /// <summary>
        /// 仓库名称
        /// </summary>
        private static string _WarehouseName { get; set; } = null!;

        /// <summary>
        ///  Http请求超时时间
        /// </summary>
        private static int _HttpTimeout { get; set; }

        /// <summary>
        ///  Http请求超时时间
        /// </summary>
        public static int HttpTimeout
        {
            get
            {
                return _HttpTimeout;
            }
        }

        /// <summary>
        /// 仓库名称
        /// </summary>
        public static string WarehouseName
        {
            get
            {
                return _WarehouseName;
            }
        }

        /// <summary>
        /// 设置仓库名称
        /// </summary>
        /// <param name="warehouseName"></param>
        public static void SetWarehouseName(string warehouseName)
        {
            _WarehouseName = warehouseName;
        }

        /// <summary>
        ///  设置Http请求超时时间
        /// </summary>
        /// <param name="timeout"></param>
        public static void SetHttpTimeout(int timeout)
        {
            _HttpTimeout = timeout;
        }

        #endregion 配置中心

        #region 系统运行模式

        /// <summary>
        /// 系统运行模式
        /// </summary>
        private static List<SystemMode> SystemModes { get; set; } = new List<SystemMode>();

        /// <summary>
        /// 添加一种模式
        /// </summary>
        /// <param name="mode">系统模式</param>
        public static void AddSystemMode(SystemMode mode)
        {
            if (SystemModes.Contains(mode)) return;
            SystemModes.Add(mode);
        }

        /// <summary>
        /// 是否包含传入模式
        /// </summary>
        /// <param name="mode">系统模式</param>
        /// <returns></returns>
        public static bool Any(SystemMode mode)
        {
            return SystemModes.Contains(mode);
        }

        #endregion 系统运行模式
    }

    /// <summary>
    /// 系统模式
    /// </summary>
    public enum SystemMode
    {
        /// <summary>
        /// 虚拟plc，启用该模式后，将在Redis中建立一个虚拟PLC用于流程测试
        /// </summary>
        虚拟plc = 1,
    }

    /// <summary>
    /// 数据库连接
    /// </summary>
    public class DataBaseConnectionString
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="key">连接对应的Key</param>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="dbType">数据库类型</param>
        /// <param name="isDefault">是否为默认数据库连接</param>
        public DataBaseConnectionString(string key, string connectionString, DbType dbType, bool isDefault)
        {
            Key = key;
            ConnectionString = connectionString;
            DbType = dbType;
            IsDefault = isDefault;
        }

        /// <summary>
        /// 连接对应的Key
        /// </summary>
        public string Key { get; set; }

        /// <summary>
        /// 连接字符串
        /// </summary>
        public string ConnectionString { get; set; }

        /// <summary>
        /// 数据库类型
        /// </summary>
        public DbType DbType { get; set; }

        /// <summary>
        /// 是否为默认数据库连接
        /// </summary>
        public bool IsDefault { get; set; }
    }
}
