using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace MemberCenter.Infrastructure.Persistence;

public class MemberCenterDbContextFactory : IDesignTimeDbContextFactory<MemberCenterDbContext>
{
    public MemberCenterDbContext CreateDbContext(string[] args)
    {
        var connectionString =
            Environment.GetEnvironmentVariable("MEMBERCENTER_CONNECTION")
            ?? Environment.GetEnvironmentVariable("ConnectionStrings__Default")
            ?? "Host=localhost;Database=member_center;Username=postgres;Password=postgres";

        var optionsBuilder = new DbContextOptionsBuilder<MemberCenterDbContext>();
        optionsBuilder.UseNpgsql(connectionString);

        return new MemberCenterDbContext(optionsBuilder.Options);
    }
}
