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

namespace SolutionErp.Infrastructure.Persistence;

// Chỉ dùng khi chạy `dotnet ef migrations` / `database update` từ CLI.
// Runtime app dùng AddDbContext trong DependencyInjection.cs.
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
{
    public ApplicationDbContext CreateDbContext(string[] args)
    {
        var options = new DbContextOptionsBuilder<ApplicationDbContext>()
            .UseSqlServer(
                "Server=(localdb)\\MSSQLLocalDB;Database=SolutionErp_Design;Trusted_Connection=True;TrustServerCertificate=true",
                sql => sql.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName))
            .Options;
        return new ApplicationDbContext(options);
    }
}
