using ZB.MOM.WW.ScadaBridge.AuditLog.Payload;
using ZB.MOM.WW.ScadaBridge.HealthMonitoring;

namespace ZB.MOM.WW.ScadaBridge.AuditLog.Site;

/// <summary>
/// Bridges
/// <see cref="IAuditRedactionFailureCounter"/> (incremented by
/// <see cref="ZB.MOM.WW.ScadaBridge.AuditLog.Redaction.ScadaBridgeAuditRedactor"/> every time
/// a header / body / SQL parameter redactor stage throws and the redactor has
/// to over-redact the offending field) into <see cref="ISiteHealthCollector"/>
/// so the count surfaces in the site health report payload as
/// <c>SiteHealthReport.AuditRedactionFailure</c>.
/// </summary>
/// <remarks>
/// <para>
/// Registered by <see cref="ServiceCollectionExtensions.AddAuditLogHealthMetricsBridge"/>;
/// callers must register <c>AddHealthMonitoring()</c> first so
/// <see cref="ISiteHealthCollector"/> resolves. The default <see cref="ServiceCollectionExtensions.AddAuditLog"/>
/// registration keeps <see cref="NoOpAuditRedactionFailureCounter"/> for nodes
/// where Site Health Monitoring is not wired (the silent-sink contract —
/// redaction failures must NEVER abort the user-facing action, alog.md §7).
/// </para>
/// <para>
/// Mirrors the <see cref="HealthMetricsAuditWriteFailureCounter"/>
/// shape one-for-one so the two health-metric bridges age together.
/// </para>
/// <para>
/// Site-side only: the redaction filter also runs on the central
/// writers (CentralAuditWriter + AuditLogIngestActor); the central
/// health-metric surface exposing <c>AuditRedactionFailure</c> is bridged
/// separately by <c>CentralAuditRedactionFailureCounter</c>, which the
/// central composition root registers in place of the NoOp default.
/// </para>
/// </remarks>
public sealed class HealthMetricsAuditRedactionFailureCounter : IAuditRedactionFailureCounter
{
    private readonly ISiteHealthCollector _collector;

    /// <summary>Initializes the counter with the site health collector it bridges into.</summary>
    /// <param name="collector">The site health collector that receives the incremented redaction-failure count.</param>
    public HealthMetricsAuditRedactionFailureCounter(ISiteHealthCollector collector)
    {
        _collector = collector ?? throw new ArgumentNullException(nameof(collector));
    }

    /// <inheritdoc/>
    public void Increment() => _collector.IncrementAuditRedactionFailure();
}
