using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;

namespace Infrastructure.Data;

public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<HealthcareManagerDatabase>
{
    public HealthcareManagerDatabase CreateDbContext(string[] args)
    {
        // Adjust the path to point to the API project directory
        var basePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\API"));

        var configuration = new ConfigurationBuilder()
            .SetBasePath(basePath)
            .AddJsonFile("appsettings.json")
            .Build();

        var builder = new DbContextOptionsBuilder<HealthcareManagerDatabase>();
        var connectionString = configuration.GetConnectionString("HealthcareManagerDatabase");

        builder.UseNpgsql(connectionString); // Make sure this matches your database provider

        return new HealthcareManagerDatabase(builder.Options);
    }
}