using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using ScadaLink.AuditLog.Configuration;
namespace ScadaLink.AuditLog;
///
/// Composition root for the Audit Log (#23) component. M1 registers
/// and its validator; later milestones extend
/// this method to wire up writers, telemetry actors, and the central ingest
/// pipeline. Audit Log (#23) sits alongside Notification Outbox (#21) and
/// Site Call Audit (#22).
///
public static class ServiceCollectionExtensions
{
/// Configuration section bound to .
public const string ConfigSectionName = "AuditLog";
///
/// Binds from the
/// section of
/// and registers so a misconfigured
/// AuditLog section is rejected with a key-naming message when the
/// options are first resolved (or at startup when consumers wire in
/// ValidateOnStart()). M2+ will register writers, telemetry actors,
/// and the central ingest pipeline here. IAuditLogRepository is
/// registered by
/// ScadaLink.ConfigurationDatabase.ServiceCollectionExtensions.AddConfigurationDatabase,
/// so the caller (the Host on the central node) must also call that.
///
public static IServiceCollection AddAuditLog(this IServiceCollection services, IConfiguration config)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(config);
services.AddOptions()
.Bind(config.GetSection(ConfigSectionName))
.ValidateOnStart();
services.AddSingleton, AuditLogOptionsValidator>();
return services;
}
}