using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.BLL;
using PARR.DAL;
using PARR.TemplateMatcher.Services.Implementations;
using PARR.TemplateMatcher.Services.Implemetaions;
using PARR.TemplateMatcher.Services.Interfaces;
using PARR.TemplateMatcher.Settings;

namespace PARR.TemplateMatcher
{
    public static class TemplateMatcherInstaller
    {
        public static void InstallTemplateMatcherSerivces(this IServiceCollection services, IConfiguration configuration)
        {
            services.InstallBllServices(configuration);
            services.InstallDalServices(configuration);

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

            services.AddTransient<IMqTemplateMatcher, MqTemplateMatcher>();
            services.AddTransient<IJobValidatorService, JobValidatorService>();
            services.AddTransient<IJobGroupValidatorService, JobGroupValidatorService>();
            services.AddTransient<ITemplateMatcher, TemplateMatcher>();
            services.AddTransient<ITemplateReuser, TemplateReuser>();
            services.AddTransient<ITemplateNameNormalizer, TemplateNameNormalizer>();
            services.AddTransient<ITemplateUpdaterMqSender, TemplateUpdaterMqSender>();
            services.AddTransient<ITemplateDeactivator, TemplateDeactivator>();
            services.AddTransient<ITemplateSynchronizer, SimpleTemplateSynchronizer>();
            services.AddTransient<ITemplateSynchronizer, GroupedTemplateSynchronizer>();
        }

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

            return builder;
        }

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