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


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

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

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

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

            return new HealthcareManagerContext(builder.Options);
        }
    }
}
