using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using YGNT.Exam.Configuration;
using YGNT.Exam.Web;

namespace YGNT.Exam.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class ExamDbContextFactory : IDesignTimeDbContextFactory<ExamDbContext>
    {
        public ExamDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<ExamDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            ExamDbContextConfigurer.Configure(builder, configuration.GetConnectionString(ExamConsts.ConnectionStringName));

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