using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.AIHITMainLoader.Context;
using PARR.AIHITMainLoader.Services;
using PARR.AIHITMainLoader.Settings;
using PARR.Infrastructure;

namespace PARR.AIHITMainLoader
{
    public static class AihitMainLoaderInstaller
    {
        public static void InstallAihitMainLoaderServices(this IServiceCollection services, IConfiguration configuration)
        {
            //services.AddCoreServices(configuration);
            services.AddInfrastructureServices(configuration);

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

            var loaderSettings = new LoaderSettings();
            configuration.GetSection(nameof(LoaderSettings)).Bind(loaderSettings);
            services.AddSingleton(loaderSettings);

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

            services.AddDbContext<AIHITContext>(options =>
                options.UseSqlServer(
                    configuration.GetConnectionString("AihitConnection"),
                    sqlServerOptions => sqlServerOptions.CommandTimeout(1800)
                ));

            services.AddTransient<IAihitService, AihitService>();
            services.AddTransient<IAihitMainLoader, AihitMainLoader>();
        }
    }
}

