using NSubstitute;
using ZB.MOM.WW.ScadaBridge.AuditLog.Site;
using ZB.MOM.WW.ScadaBridge.HealthMonitoring;

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

/// <summary>
/// Bundle C (M5-T7) — the <see cref="HealthMetricsAuditRedactionFailureCounter"/>
/// adapter is the production binding for
/// <see cref="ZB.MOM.WW.ScadaBridge.AuditLog.Payload.IAuditRedactionFailureCounter"/> on
/// site nodes; it forwards every <see cref="ZB.MOM.WW.ScadaBridge.AuditLog.Redaction.ScadaBridgeAuditRedactor"/>
/// redactor over-redaction event into the shared
/// <see cref="ISiteHealthCollector"/> so the site health report surfaces the
/// count as <c>AuditRedactionFailure</c>. Mirrors the M2 Bundle G
/// HealthMetricsAuditWriteFailureCounter shape one-for-one.
/// </summary>
public class HealthMetricsAuditRedactionFailureCounterTests
{
    [Fact]
    public void Increment_Routes_To_Collector_IncrementAuditRedactionFailure()
    {
        var collector = Substitute.For<ISiteHealthCollector>();
        var counter = new HealthMetricsAuditRedactionFailureCounter(collector);

        counter.Increment();

        collector.Received(1).IncrementAuditRedactionFailure();
    }

    [Fact]
    public void Increment_Multiple_Calls_Route_To_Collector_Each_Time()
    {
        var collector = Substitute.For<ISiteHealthCollector>();
        var counter = new HealthMetricsAuditRedactionFailureCounter(collector);

        counter.Increment();
        counter.Increment();
        counter.Increment();

        collector.Received(3).IncrementAuditRedactionFailure();
    }

    [Fact]
    public void Construction_With_Null_Collector_Throws_ArgumentNullException()
    {
        Assert.Throws<ArgumentNullException>(
            () => new HealthMetricsAuditRedactionFailureCounter(null!));
    }
}
