namespace ZB.MOM.WW.Audit;

/// <summary>Decorator: applies an <see cref="IAuditRedactor"/>, then delegates to an inner <see cref="IAuditWriter"/>.</summary>
public sealed class RedactingAuditWriter : IAuditWriter
{
    private readonly IAuditRedactor _redactor;
    private readonly IAuditWriter _inner;

    /// <summary>Creates the decorator around <paramref name="inner"/> using <paramref name="redactor"/>.</summary>
    public RedactingAuditWriter(IAuditRedactor redactor, IAuditWriter inner)
    {
        ArgumentNullException.ThrowIfNull(redactor);
        ArgumentNullException.ThrowIfNull(inner);
        _redactor = redactor;
        _inner = inner;
    }

    /// <inheritdoc />
    public Task WriteAsync(AuditEvent evt, CancellationToken ct = default)
    {
        ArgumentNullException.ThrowIfNull(evt);
        return _inner.WriteAsync(_redactor.Apply(evt), ct);
    }
}
