namespace Common.WebApi;

public static class DependencyInjectionExtensions
{
    public static IServiceCollection AddApplicationDatabase(this IServiceCollection services, string? connectionString)
    {
        if (string.IsNullOrWhiteSpace(connectionString)) throw new ArgumentNullException(nameof(connectionString));

        services.AddDbContext<UserDbContext>(options =>
        {
            options.UseNpgsql(connectionString, q =>
            {
                q.MigrationsAssembly(Assembly.GetAssembly(typeof(UserDbContext))!.GetName().Name);
                q.MigrationsHistoryTable("__Migrations");
            });
            //options.UseNpgsql(connectionString);
            //AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); //Включаем UTC-время.
            //options.UseLazyLoadingProxies(); // lazy loading
        });
        AddRepositories(services);
        // AddGateways(services);
        return services;
    }
}