using System.Collections.Concurrent;
using ZB.MOM.WW.MxGateway.Contracts.Proto;
using ZB.MOM.WW.MxGateway.Server.Dashboard.Hubs;

namespace ZB.MOM.WW.MxGateway.Tests.TestSupport;

/// <summary>
/// <see cref="IDashboardEventBroadcaster"/> test double that captures every
/// <c>Publish(sessionId, mxEvent)</c> call into a thread-safe list, so tests
/// can prove the gRPC producer loop actually mirrors events to the dashboard
/// fan-out seam.
/// </summary>
public sealed class RecordingDashboardEventBroadcaster : IDashboardEventBroadcaster
{
    private readonly ConcurrentQueue<DashboardEventCapture> _captures = new();

    /// <summary>Gets a snapshot of every <c>Publish</c> call in arrival order.</summary>
    public IReadOnlyList<DashboardEventCapture> Captures => _captures.ToArray();

    /// <inheritdoc />
    public void Publish(string sessionId, MxEvent mxEvent)
    {
        _captures.Enqueue(new DashboardEventCapture(sessionId, mxEvent));
    }
}

/// <summary>Captured <c>(sessionId, mxEvent)</c> pair from a Publish invocation.</summary>
/// <param name="SessionId">The session id passed to Publish.</param>
/// <param name="MxEvent">The MxEvent passed to Publish.</param>
public sealed record DashboardEventCapture(string SessionId, MxEvent MxEvent);
