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

namespace PARR.EsppOrderManager
{
    public static class ParrEsppOrderManagerInstaller
    {
        public static void InstallEsppOrderManagerServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddDalServices(configuration);
            services.InstallEsppApiServices(configuration);
            services.AddCoreServices(configuration);
            services.AddInfrastructureServices(configuration);

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

            var esppPoligonSettings = new EsppPoligonSettings();
            configuration.GetSection(nameof(EsppPoligonSettings)).Bind(esppPoligonSettings);
            services.AddSingleton(esppPoligonSettings);

            var resultTemplateSettings = new ResultTemplateSettings();
            configuration.GetSection(nameof(ResultTemplateSettings)).Bind(resultTemplateSettings);
            services.AddSingleton(resultTemplateSettings);

            services.AddTransient<IEsppOrderManager, EsppOrderManager>();
            services.AddTransient<IEsppOrderService, EsppOrderService>();
        }

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

            return builder;
        }

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