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

namespace PARR.TemplateDistributor
{
    public static class TemplateDistributorInstaller
    {
        public static void InstallTemplateDistributorSerivces(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddDalServices(configuration);
            services.AddCoreServices(configuration);
            services.AddInfrastructureServices(configuration);

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

            services.AddTransient<ITemplateDistributor, TemplateDistributor>();
            services.AddTransient<IMqTemplateDistributor, MqTemplateDistributor>();
            services.AddTransient<IValidatorService, ValidatorService>();
        }

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

            return builder;
        }

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