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

namespace PARR.TemplateUpdater
{
    public static class TemplateUpdaterInstaller
    {
        public static void InstallTemplateUpdaterServices(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<ITemplateUpdater, TemplateUpdater>();
            services.AddTransient<ITemplateUpdaterService, TemplateUpdaterService>();
        }

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

            return builder;
        }

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