using Abp.EntityFrameworkCore;
using Abp.EntityFrameworkCore.Configuration;
using Abp.Extensions;
using Abp.Modules;
using Abp.Reflection.Extensions;
using Abp.Zero.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using YGNT.Infrastructure.Helper;
using YGNT.QuestionLibrary.Core;
using YGNT.QuestionLibrary.EntityFrameworkCore.Seed;

namespace YGNT.QuestionLibrary.EntityFrameworkCore
{
    [DependsOn(
        typeof(QuestionLibraryCoreModule),
        typeof(AbpZeroCoreEntityFrameworkCoreModule))]
    public class QuestionLibraryEntityFrameworkCoreModule : AbpModule
    {

        //public override void PreInitialize()
        //{

        //    var configuration = IocManager.Resolve<IConfigurationRoot>();
        //    var connectionString = configuration.GetConnectionString(QuestionLibraryConsts.ConnectionStringName);
        //    Configuration.Modules.AbpEfCore()
        //        .AddDbContext<QuestionLibraryDbContext>(options =>
        //        {
        //            DbContextOptionsConfigurer.Configure(options.DbContextOptions, connectionString);
        //        });
        //}

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(QuestionLibraryEntityFrameworkCoreModule).GetAssembly());
        }

        public override void PostInitialize()
        {
            var skipDbSeed = AppSettings.App("DbSetting", "SkipDbSeed").To<bool>();
            if (!skipDbSeed)
            {
                SeedHelper.SeedHostDb(IocManager);
            }
        }
    }
}