using AutopilotMonitor.Shared.DataAccess;
using AutopilotMonitor.Functions.DataAccess.TableStorage;
using Microsoft.Extensions.DependencyInjection;
namespace AutopilotMonitor.Functions.DataAccess
{
///
/// Extension methods for registering Data Access Layer services.
/// Currently registers Azure Table Storage implementations.
/// To switch to Cosmos DB, replace the implementation registrations here.
///
public static class DataAccessServiceExtensions
{
///
/// Registers all Data Access Layer services with Table Storage implementations.
///
public static IServiceCollection AddTableStorageDataAccess(this IServiceCollection services)
{
// Event publisher (no-op by default; replace with Event Hub/Service Bus implementation)
services.AddSingleton();
// Storage initializer
services.AddSingleton();
// Repository implementations (delegate to existing TableStorageService)
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
// V2 Decision Engine repositories (Plan §M5).
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
// Tenant-offboarding audit (Marker / History / ByTenant pointer).
services.AddSingleton();
// Tenant-offboarding customs archive (PR3.B): snapshot of GatherRules /
// AnalyzeRules / ImeLogPatterns rows that were wiped during Phase 2.D-archive,
// surfaced via the Global Admin /admin/customs-archive page.
services.AddSingleton();
// Pre-write snapshots of TenantConfiguration/AdminConfiguration rows;
// constructor dependency of TableConfigRepository's save hook.
services.AddSingleton();
// Graph add-on permission feature: per-tenant cache of Intune script display names.
services.AddSingleton();
return services;
}
///
/// Replaces the default NullDataEventPublisher with a custom implementation.
/// Call this AFTER AddTableStorageDataAccess() to override.
/// Example: services.AddEventStreaming<EventHubPublisher>();
///
public static IServiceCollection AddEventStreaming(this IServiceCollection services)
where TPublisher : class, IDataEventPublisher
{
// Remove existing registration and replace
var descriptor = services.FirstOrDefault(d => d.ServiceType == typeof(IDataEventPublisher));
if (descriptor != null)
services.Remove(descriptor);
services.AddSingleton();
return services;
}
}
}