using ZB.MOM.WW.Secrets.Abstractions;

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

/// <summary>
/// The subset of store operations hub replication needs from the shared database: compare
/// inventories, fetch rows in bulk, and accept a row verbatim.
/// </summary>
/// <remarks>
/// Narrower than <see cref="ISecretStore"/> on purpose. The hub is never resolved from, never
/// written through <see cref="ISecretStore.UpsertAsync"/> (which would stamp the hub's own revision
/// and bounce the row back), and never rewrapped by a syncing node — so exposing those operations
/// would only create ways to use it wrongly. It also makes the sync sweep testable against an
/// in-process fake instead of requiring a live SQL Server for every convergence case.
/// </remarks>
public interface ISecretReplicationHub
{
    /// <summary>Returns the hub's manifest — names, revisions, timestamps, tombstone flags.</summary>
    /// <param name="ct">A token to cancel the operation.</param>
    /// <returns>The hub's manifest entries.</returns>
    Task<IReadOnlyList<SecretManifestEntry>> GetManifestAsync(CancellationToken ct);

    /// <summary>Fetches several encrypted rows by name; names absent from the hub are omitted.</summary>
    /// <param name="names">The names to fetch.</param>
    /// <param name="ct">A token to cancel the operation.</param>
    /// <returns>The matching encrypted rows.</returns>
    Task<IReadOnlyList<StoredSecret>> GetManyAsync(IReadOnlyList<SecretName> names, CancellationToken ct);

    /// <summary>Applies a row to the hub verbatim, last-writer-wins.</summary>
    /// <param name="row">The encrypted row.</param>
    /// <param name="ct">A token to cancel the operation.</param>
    /// <returns>A task that completes when the row has been applied or ignored.</returns>
    Task ApplyReplicatedAsync(StoredSecret row, CancellationToken ct);
}
