using Modules.Common.Imports.Jobs;
using Modules.OMS.Orders.Import;

namespace Shared.Excel;

public static class KbxExcelImportRegistration
{
    public static IServiceCollection AddKbxExcelImport(this IServiceCollection services)
    {
        services.AddSignalR();
        services.AddSingleton<XlsxSafetyInspector>();
        services.AddSingleton<ClosedXmlWorkbookService>();
        services.AddSingleton<ImportMappingEngine>();
        services.AddSingleton<ImportRepository>();
        services.AddSingleton<IImportMappingSuggester, NoopImportMappingSuggester>();
        services.AddSingleton<IImportDefinition, OrderImportDefinition>();
        services.AddSingleton<ImportDefinitionRegistry>();
        services.AddSingleton<ImportProgressPublisher>();
        services.AddTransient<ValidateImportJob>();
        services.AddTransient<CommitImportJob>();
        services.AddTransient<PurgeExpiredImportsJob>();
        return services;
    }

    public static IEndpointRouteBuilder MapKbxExcelImport(this IEndpointRouteBuilder endpoints)
    {
        endpoints.MapHub<ImportProgressHub>("/hubs/import-progress");
        return endpoints;
    }
}
