using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;

namespace Hotline.Tests.SqlSuger;
public static class CAPDbExtensions
{
    public static IServiceCollection AddCAPDb(this IServiceCollection services, IConfiguration configuration)
    {
        var config = configuration.GetConnectionString("CAP");
        SqlSugarScope sqlSugar = new(new ConnectionConfig() 
        { 
            DbType = DbType.PostgreSQL,
            ConnectionString = configuration.GetConnectionString("CAP"),
            IsAutoCloseConnection = true,
            InitKeyType = InitKeyType.Attribute,
            MoreSettings = new ConnMoreSettings()
            {
                PgSqlIsAutoToLower = false
            }
        });

        ISugarUnitOfWork<CapDbContext> context = new SugarUnitOfWork<CapDbContext>(sqlSugar);
        services.AddSingleton(context);
        return services;
    }
}
