using ContingencyManagement.Sdk;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;

namespace DataSharing.Repository.Extensions
{
    public static class ContingencyManagementDbExtensions
    {
        public static void AddYingJiDb(this IServiceCollection services, YingJiGuanLiJuConfiguration yingJiGuanLiJuConfiguration)
        {
            SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
            {
                DbType = DbType.MySql,
                ConnectionString = yingJiGuanLiJuConfiguration.DbConnectionString,
                IsAutoCloseConnection = true,
            },
                 db => { }
             );

            ISugarUnitOfWork<ContingencyManagementDbContext> context = new SugarUnitOfWork<ContingencyManagementDbContext>(sqlSugar);
            services.AddSingleton(context);
            context.Db.DbMaintenance.CreateDatabase();

            context.Db.CodeFirst.InitTables(typeof(ContingencyManagementOrders));
         //   return services;
        }
    }
}
