using System.Collections.Concurrent;
using ZB.MOM.WW.Audit;

namespace ZB.MOM.WW.Secrets.Tests.Fakes;

/// <summary>
/// An <see cref="IAuditWriter"/> test double that collects every <see cref="AuditEvent"/> written,
/// so a test can assert on the audit trail (outcome, target, and — critically — that no plaintext
/// ever appears in any field).
/// </summary>
public sealed class CapturingAuditWriter : IAuditWriter
{
    private readonly ConcurrentQueue<AuditEvent> _events = new();

    /// <summary>The events captured so far, in write order.</summary>
    public IReadOnlyList<AuditEvent> Events => _events.ToArray();

    /// <inheritdoc />
    public Task WriteAsync(AuditEvent evt, CancellationToken ct = default)
    {
        _events.Enqueue(evt);
        return Task.CompletedTask;
    }
}
