using Hotline.CallCenter.Configs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;

namespace Hotline.Repository.SqlSugar.Extensions;

public static class XingTangDbExtensions
{
    public static IServiceCollection AddXingTangDb(this IServiceCollection services, XingTangConfiguration xingTangConfiguration)
    {
        SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
        {
            DbType = DbType.PostgreSQL,
            ConnectionString = xingTangConfiguration.DbConnectionString,
            IsAutoCloseConnection = true,
            //ConfigureExternalServices = new ConfigureExternalServices()
            //{
            //    EntityService = (x, p) => //处理列名
            //    {
            //        p.DbColumnName = string.IsNullOrEmpty(p.DbColumnName) ? p.DbColumnName : p.DbColumnName.ToLower(); 
            //        //UtilMethods.ToUnderLine(p.DbColumnName);//ToUnderLine驼峰转下划线方法
            //    },
            //    EntityNameService = (x, p) => //处理表名
            //    {
            //    }
            //}
        },
             db => { }
         );

        ISugarUnitOfWork<XingTangDbContext> context = new SugarUnitOfWork<XingTangDbContext>(sqlSugar);
        services.AddSingleton(context);

        return services;
    }
}