using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.AIHITMainSyncer.Services;
using PARR.AIHITMainSyncer.Settings;
using PARR.Core;
using PARR.DAL;
using PARR.Infrastructure;

namespace PARR.AIHITMainSyncer
{
    public static class AihitMainSyncerInstaller
    {
        public static void InstallAihitMainSyncerServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddDalServices(configuration);
            services.AddCoreServices(configuration);
            services.AddInfrastructureServices(configuration);

            var settings = new WorkerSettings();
            configuration.GetSection(nameof(WorkerSettings)).Bind(settings);
            services.AddSingleton(settings);

            var mqSettings = new MqSettings();
            configuration.GetSection(nameof(MqSettings)).Bind(mqSettings);
            services.AddSingleton(mqSettings);

            var fieldValueReplacementsSettings = new FieldValueReplacementsSettings();
            configuration.GetSection(nameof(FieldValueReplacementsSettings)).Bind(fieldValueReplacementsSettings);
            services.AddSingleton(fieldValueReplacementsSettings);

            services.AddTransient<IAihitMainSyncer, AihitMainSyncer>();
            services.AddTransient<ISyncerService, SyncerService>();
        }


        public static IConfigurationBuilder AddAihitMainSyncerConfigurations(this IConfigurationBuilder builder, IServiceCollection services)
        {
            builder.AddDalConfigurations(services);

            return builder;
        }


        public static void AddAihitMainSyncerSettings(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddDallSettings(configuration);
        }
    }
}
