using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using SatelliteProvider.Common.Configs;
using SatelliteProvider.Common.Interfaces;

namespace SatelliteProvider.Services.RegionProcessing;

public static class RegionProcessingServiceCollectionExtensions
{
    public static IServiceCollection AddRegionProcessing(this IServiceCollection services)
    {
        services.AddSingleton<IRegionRequestQueue>(sp =>
        {
            var processingConfig = sp.GetRequiredService<IOptions<ProcessingConfig>>().Value;
            var logger = sp.GetRequiredService<ILogger<RegionRequestQueue>>();
            return new RegionRequestQueue(processingConfig.QueueCapacity, logger);
        });
        services.AddSingleton<IRegionService, RegionService>();
        services.AddHostedService<RegionProcessingService>();
        return services;
    }
}
