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 G (M2-T11) — the <see cref="HealthMetricsAuditWriteFailureCounter"/>
/// adapter is the production binding for <see cref="IAuditWriteFailureCounter"/>
/// on site nodes; it forwards every FallbackAuditWriter primary failure into
/// the shared <see cref="ISiteHealthCollector"/> so the site health report
/// surfaces the failure count as <c>SiteAuditWriteFailures</c>.
/// </summary>
public class HealthMetricsAuditWriteFailureCounterTests
{
    [Fact]
    public void Increment_Routes_To_Collector_IncrementSiteAuditWriteFailures()
    {
        var collector = Substitute.For<ISiteHealthCollector>();
        var counter = new HealthMetricsAuditWriteFailureCounter(collector);

        counter.Increment();

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

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

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

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

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