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

namespace Jiaowu.Api.Infrastructure.Persistence;

public sealed class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
    public AppDbContext CreateDbContext(string[] args)
    {
        var connectionString =
            Environment.GetEnvironmentVariable("ConnectionStrings__MySql")
            ?? "Server=localhost;Port=3306;Database=jiaowu;User=__design_time__;Password=__not_used__;";

        var options = new DbContextOptionsBuilder<AppDbContext>()
            .UseMySQL(MySqlConnectionStringPolicy.ForApplication(connectionString))
            .Options;

        return new AppDbContext(options);
    }
}
