using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using MineTec.ProManager.Configuration;
using MineTec.ProManager.Web;

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

            ProManagerDbContextConfigurer.Configure(builder, configuration.GetConnectionString(ProManagerConsts.ConnectionStringName));

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