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

namespace PARR.EsppScheduleSync
{
    public static class EsppScheduleSyncInstaller
    {
        public static void InstallEsppScheduleSyncServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.InstallEsppSyncServices<EsppObjectSchedule>(configuration);
            services.AddCoreServices(configuration);
            services.AddInfrastructureServices(configuration);

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

            services.AddTransient<IScheduleSyncher, ScheduleSyncher>();
        }

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

            return builder;
        }

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