using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.AIHITSyncer.Services;
using PARR.AIHITSyncer.Settings;
using PARR.BLL;
using PARR.DAL;

namespace PARR.AIHITSyncer
{
    public static class AihitSyncerInstaller
    {
        public static void InstallAihitSyncerServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.InstallBllServices(configuration);
            services.InstallDalServices(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);

            services.AddTransient<IAihitSyncer, AihitSyncer>();
            services.AddTransient<ISyncerService, SyncerService>();
        }

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

            return builder;
        }

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