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

namespace PARR.TemplateTaskGenerator
{
    public static class TemplateTaskGeneratorInstaller
    {
        public static void InstallTemplateTaskGeneratorSerivces(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<IMqTemplateTaskGenerator, MqTemplateTaskGenerator>();
            services.AddTransient<IValidatorService, ValidatorService>();
            services.AddTransient<ITemplateTaskGenerator, TemplateTaskGenerator>();
        }

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

            return builder;
        }

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