using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.Core;
using PARR.DAL;
using PARR.EsppSync;
using PARR.EsppTemplateSync.Domain;
using PARR.EsppTemplateSync.Settings;
using PARR.Infrastructure;

namespace PARR.EsppTemplateSync
{
    public static class EsppTemplateSyncInstaller
    {
        public static void InstallEsppTemplateSyncServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddDalServices(configuration);
            services.InstallEsppSyncServices<EsppObjectTemplate>(configuration);
            services.AddCoreServices(configuration);
            services.AddInfrastructureServices(configuration);

            var globalSettings = new GlobalSettings();
            configuration.GetSection(nameof(GlobalSettings)).Bind(globalSettings);
            services.AddSingleton(globalSettings);

            services.AddTransient<ITemplateSyncer, TemplateMQSyncer>();
        }

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

            return builder;
        }

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