using ZB.MOM.WW.Secrets.Abstractions;

namespace ZB.MOM.WW.Secrets.Replicator.SqlServer;

/// <summary>
/// Publishes local writes to the shared SQL-Server hub, so a secret written on one node is
/// immediately visible to every other node that syncs against the same hub.
/// </summary>
/// <remarks>
/// The row is written through <see cref="ISecretStore.ApplyReplicatedAsync"/>, not
/// <see cref="ISecretStore.UpsertAsync"/> — the hub must record the row <em>verbatim</em>, keeping
/// the originating node's revision and <c>updated_utc</c>. An upsert would stamp the hub's own
/// revision and timestamp, and the row would then look newer than the writer's own copy, so it
/// would bounce straight back on the next sync.
/// </remarks>
/// <param name="hub">The shared hub store.</param>
public sealed class SqlServerSecretReplicator(ISecretReplicationHub hub) : ISecretReplicator
{
    /// <inheritdoc />
    public Task PublishAsync(StoredSecret row, CancellationToken ct)
    {
        ArgumentNullException.ThrowIfNull(row);

        return hub.ApplyReplicatedAsync(row, ct);
    }
}
