using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.Core;
using PARR.DAL;
using PARR.Infrastructure;
using PARR.Master.Services;
using PARR.Master.Settings;

namespace PARR.Master
{
    public static class ParrMasterInstaller
    {
        public static void InstallMasterServices(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);

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

            var orderManageSettings = new OrderManageSettings();
            configuration.GetSection(nameof(OrderManageSettings)).Bind(orderManageSettings);
            services.AddSingleton(orderManageSettings);

            //add other services
            services.AddTransient<IMaster, Master>();
            services.AddTransient<IOrderMasterService, OrderMasterService>();
        }

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

            return builder;
        }

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