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

namespace PARR.EsppOrderLoader
{
    public static class ParrEsppOrderLoaderInstaller
    {
        public static void InstallEsppOrderLoaderServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddDalServices(configuration);
            services.InstallEsppApiServices(configuration);
            services.AddInfrastructureServices(configuration);

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

            services.AddTransient<IEsppOrderLoader, EsppOrderLoader>();
            services.AddTransient<IOrderItemService, OrderItemService>();
        }

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

            return builder;
        }

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