using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.Core;
using PARR.DAL;
using PARR.Infrastructure;
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.AddDalServices(configuration);
            services.AddCoreServices(configuration);
            services.AddInfrastructureServices(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);
        }
    }
}
