using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Nexus.Api.Data;

namespace Nexus.Api;

public class NexusDbContextFactory : IDesignTimeDbContextFactory<NexusDbContext>
{
    public NexusDbContext CreateDbContext(string[] args)
    {
        var optionsBuilder = new DbContextOptionsBuilder<NexusDbContext>();
        var connectionString = args.Length > 0
            ? args[0]
            : Environment.GetEnvironmentVariable("ConnectionStrings__Nexus")
              ?? "Host=localhost;Port=5432;Database=nexus;Username=nexus;Password=nexus";

        optionsBuilder.UseNpgsql(connectionString);
        return new NexusDbContext(optionsBuilder.Options);
    }
}
