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

public class PhotoShareDbContextFactory : IDesignTimeDbContextFactory<PhotoShareDbContext>
{
    public PhotoShareDbContext CreateDbContext(string[] args)
    {
        // Récupère la configuration depuis appsettings.json
        var configuration = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json")
            .Build();

        var optionsBuilder = new DbContextOptionsBuilder<PhotoShareDbContext>();
        var connectionString = configuration.GetConnectionString("DefaultConnection");

        optionsBuilder.UseNpgsql(connectionString);

        return new PhotoShareDbContext(optionsBuilder.Options);
    }
}
