using Hcs.Broker;
using Hcs.Service.Async.Nsi;
using Hcs.WebApp.Data.Hcs;
using Hcs.WebApp.Services;

namespace Hcs.WebApp.BackgroundServices.OperationExecutors.Nsi
{
    public class ExportDataProviderNsiItemExecutor_15_7_0_1(IClient client, IServiceScope scope, Operation operation) : ExecutorBase(client, scope, operation)
    {
        public override async Task<string> ExecuteAsync(CancellationToken cancellationToken)
        {
            var registryService = scope.ServiceProvider.GetRequiredService<RegistryService>();
            var registry = await registryService.GetRegistryByOperationIdAsync(operation.Id);
            var number = RegistryNumberFromInt(registry.Number);
            return await client.Nsi.RequestExportDataProviderNsiItemAsync(number, cancellationToken);
        }

        private exportDataProviderNsiItemRequestRegistryNumber RegistryNumberFromInt(int number)
        {
            return number switch
            {
                1 => exportDataProviderNsiItemRequestRegistryNumber.Item1,
                51 => exportDataProviderNsiItemRequestRegistryNumber.Item51,
                59 => exportDataProviderNsiItemRequestRegistryNumber.Item59,
                219 => exportDataProviderNsiItemRequestRegistryNumber.Item219,
                272 => exportDataProviderNsiItemRequestRegistryNumber.Item272,
                302 => exportDataProviderNsiItemRequestRegistryNumber.Item302,
                337 => exportDataProviderNsiItemRequestRegistryNumber.Item337,

                _ => throw new ArgumentException($"Не удалось получить номер справочника из значения {number}"),
            };
        }
    }
}
