using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace ZB.MOM.WW.Audit;

/// <summary>DI helpers for ZB.MOM.WW.Audit.</summary>
public static class AuditServiceCollectionExtensions
{
    /// <summary>
    /// Registers safe defaults — <see cref="NullAuditRedactor"/> and <see cref="NoOpAuditWriter"/> —
    /// using TryAdd so a consumer that has already registered a real writer/redactor wins. Consumers
    /// compose <see cref="RedactingAuditWriter"/>/<see cref="CompositeAuditWriter"/> around their own sink.
    /// </summary>
    public static IServiceCollection AddZbAudit(this IServiceCollection services)
    {
        ArgumentNullException.ThrowIfNull(services);
        services.TryAddSingleton<IAuditRedactor>(NullAuditRedactor.Instance);
        services.TryAddSingleton<IAuditWriter>(NoOpAuditWriter.Instance);
        return services;
    }
}
