using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.AIHITRelationshipsSyncer.Context;
using PARR.AIHITRelationshipsSyncer.Services.Implementations;
using PARR.AIHITRelationshipsSyncer.Services.Interfaces;
using PARR.AIHITRelationshipsSyncer.Settings;
using PARR.Core;
using PARR.DAL;
using PARR.Infrastructure;

namespace PARR.AIHITRelationshipsSyncer
{
    public static class AihitRelationshpsSyncerInstaller
    {
        public static void InstallAihitRelationshpsSyncerServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddDalServices(configuration);
            services.AddCoreServices(configuration);
            services.AddInfrastructureServices(configuration);
           
            var settings = new WorkerSettings();
            configuration.GetSection(nameof(WorkerSettings)).Bind(settings);
            services.AddSingleton(settings);

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

            services.AddTransient<IRelationshipsSyncer, RelationshipsSyncer>();
            services.AddTransient<IAihitService, AihitService>();
            services.AddTransient<IRelationshipsSyncService, RelationshipsSyncService>();
        }


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

            return builder;
        }


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