using Microsoft.Extensions.Configuration.Json;
using OASystem.Domain.Dtos.Groups;
using OASystem.Domain.Dtos.Business;

namespace OASystem.API.OAMethodLib
{
    public class AutofacRegister : Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            //OASystem.Infrastructure中所有以Repository结尾的文件都会被注入到项目
            var assemblyServices = Assembly.Load("OASystem.Infrastructure");
            builder.RegisterAssemblyTypes(assemblyServices).Where(a => a.Name.EndsWith("Repository")).AsSelf();

            #region 团组流程管控配置

            GroupsConfig _groupsConfig = new GroupsConfig();
            _groupsConfig.AutoCreate = int.Parse(AppSettingsHelper.Get(GroupsConfig.KEY, "AutoCreate"));
            _groupsConfig.Leader = int.Parse(AppSettingsHelper.Get(GroupsConfig.KEY, "Leader"));
            _groupsConfig.ExBeginDays = int.Parse(AppSettingsHelper.Get(GroupsConfig.KEY, "ExBeginDays"));
            _groupsConfig.ExEndDays = int.Parse(AppSettingsHelper.Get(GroupsConfig.KEY, "ExEndDays"));
            _groupsConfig.DefaultUser = int.Parse(AppSettingsHelper.Get(GroupsConfig.KEY, "DefaultUser"));
            _groupsConfig.Boss = int.Parse(AppSettingsHelper.Get(GroupsConfig.KEY, "Boss"));
            _groupsConfig.FilterUser = AppSettingsHelper.Get(GroupsConfig.KEY, "FilterUser");
            builder.RegisterInstance<GroupsConfig>(_groupsConfig);
            #endregion

            #region 团组结束通知短信
            DeleReminderConfig _deleReminderConfig = new DeleReminderConfig();
            _deleReminderConfig.Test= AppSettingsHelper.Get(DeleReminderConfig.KEY, "Test");
            _deleReminderConfig.PhoneNumber= AppSettingsHelper.Get(DeleReminderConfig.KEY, "PhoneNumber");
            builder.RegisterInstance<DeleReminderConfig>(_deleReminderConfig);
            #endregion

        }
    }
}
