using Microsoft.Extensions.Options; using Somnia.GuestLog.Enums.Models; using Somnia.GuestLog.Models.Configuration; using Somnia.GuestLog.Utils.DI; namespace Somnia.GuestLog.Services.StayExport; public class StayExportFormatProviderFactory( IServiceProvider serviceProvider, IOptions config ) : IStayExportFormatProviderFactory, IFactoryDI { public static void RegisterFactoryItems(IServiceCollection services) { services.AddKeyedSingleton(StayExportFormat.GuestLogJson); services.AddKeyedSingleton(StayExportFormat.SpainParteViajeros); } public IStayExportFormatProvider GetProvider(StayExportFormat exportFormat) { if (config.Value.EnableStayExport == false) { throw new InvalidOperationException("StayExport is disabled. Enable and configure it first!"); } return serviceProvider.GetKeyedService(exportFormat) ?? throw new InvalidOperationException($"StayExport service not found for ExportFormat: '{exportFormat}'"); } }