using System.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using YGNT.QuestionLibrary.Core;
using YGNT.QuestionLibrary.Core.Configuration;

namespace YGNT.QuestionLibrary.EntityFrameworkCore
{
    /* This class is needed to run EF Core PMC commands. Not used anywhere else */
    public class QuestionLibraryDbContextFactory : IDesignTimeDbContextFactory<QuestionLibraryDbContext>
    {
        public QuestionLibraryDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<QuestionLibraryDbContext>();
            
            var configuration = AppConfigurations.Get(Directory.GetCurrentDirectory());

            DbContextOptionsConfigurer.Configure(
                builder,
                configuration.GetConnectionString(QuestionLibraryConsts.ConnectionStringName)
            );

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