using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using ReAct_PME.Infrastructure.Persistence;


namespace ReAct_PME.Infrastructure
{
    public partial class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
    {
		public AppDbContext CreateDbContext(string[] args)
		{
			string path = Path.Combine(Directory.GetCurrentDirectory(), "../ReAct_PME.Api");
			var configuration = new ConfigurationBuilder()
				.SetBasePath(path) // Accède au projet API
				.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
				.Build();

			var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
			optionsBuilder.UseSqlServer(configuration.GetConnectionString("DefaultConnection"));

			return new AppDbContext(optionsBuilder.Options);
		}



    }
}
