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

namespace PARR.NextRun
{
    public static class NextRunInstaller
    {
        public static void InstallNextRunServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddDalServices(configuration);
            services.AddCoreServices(configuration);
            services.AddInfrastructureServices(configuration);

            var settings = new WorkerSettings();
            configuration.GetSection(nameof(WorkerSettings)).Bind(settings);
            services.AddSingleton(settings);

            services.AddTransient<INextRunIntervalService, NextRunIntervalService>();
            services.AddTransient<INextRunRabbitService, NextRunRabbitService>();
            services.AddTransient<INextRunUpdateService, NextRunUpdateService>();
        }


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

            return builder;
        }


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