using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Common.Postgres;
public static class DependencyInjectionExtensions
{
	public static IServiceCollection AddPostgres<T>(
		this IServiceCollection services,
		string connectionString)
		where T : DbContext
	{
		_ = services.AddDbContext<T>(options =>
		{
			_ = options.UseNpgsql(connectionString)
				.LogTo(Console.WriteLine, LogLevel.Warning)
				.EnableSensitiveDataLogging(false);
		});

		return services;
	}
}
