using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Host.Drivers;

namespace ZB.MOM.WW.OtOpcUa.Host.IntegrationTests;

/// <summary>
///     Guards that the resilience-status tracker now HAS a production reader — the exact
///     "built-but-never-wired" class of bug the whole arch-review targets (mirrors
///     <see cref="ResilienceInvokerFactoryRegistrationTests"/>). <c>AddOtOpcUaDriverFactories</c> (the
///     driver-node bootstrap) must register <see cref="DriverResilienceStatusPublisherService"/> as an
///     <see cref="IHostedService"/>. A refactor that drops the registration fails this test, not production.
/// </summary>
public sealed class ResilienceStatusReaderRegistrationTests
{
    [Fact]
    public void AddOtOpcUaDriverFactories_registers_the_resilience_status_reader_hosted_service()
    {
        var services = new ServiceCollection();
        services.AddLogging();
        services.AddOtOpcUaDriverFactories();

        services.ShouldContain(
            d => d.ServiceType == typeof(IHostedService)
                 && d.ImplementationType == typeof(DriverResilienceStatusPublisherService),
            "the resilience-status tracker must have a production reader — the periodic DPS publisher hosted service on driver nodes");
    }
}
