using HTCoreServiceApp.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HTCoreServiceApp.Common;
using SqlSugar;

namespace HTCoreServiceApp.Common
{
    public static class StaticLibrary
    {

        static ConnectionConfig _DBConfig;

        public static ConnectionConfig DBConfig
        {
            get
            {
                if (_DBConfig == null)
                {
                    string ConnectionStrings = AESKeyEncrypt.DecryptDES(ConfigHelper.ReadAppSettings("ConnectionStrings", "SqlServer"));
                    //_DBConfig = new ScadaContext(ConnectionStrings);
                    _DBConfig = new ConnectionConfig()
                    {
                        IsAutoCloseConnection = true,
                        DbType = DbType.SqlServer,
                        ConfigId = 0,
                        ConnectionString = ConnectionStrings
                    };
                }
                return _DBConfig;
            }
            set => _DBConfig = value; 
        }

        static DriverService _HTDataService;

        public static DriverService HTDataService
        {
            get
            {
                if (_HTDataService == null)
                    _HTDataService = new DriverService();
                return _HTDataService;
            }
            set => _HTDataService = value;
        }

        //private static IMemoryCache cache;
        private static IDistributedCache _MemoryCacheHelper;
        public static IDistributedCache MemoryCacheHelper
        {
            get
            {
                if (_MemoryCacheHelper == null)
                {
                    _MemoryCacheHelper= new RedisCache(new RedisCacheOptions() { 
                        Configuration = "127.0.0.1:6379",
                        InstanceName = ""
                    });
                }
                return _MemoryCacheHelper;
            }
            
        }

        public static MemoryCache _MemoryCache;
        public static MemoryCache MemoryCache
        {
            get
            {
                if (_MemoryCache == null)
                {
                    _MemoryCache = new MemoryCache(new MemoryCacheOptions()
                    {

                    });
                }
                return (_MemoryCache);
            }
        }
    }
}
