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

/// <summary>
/// Configuration for peer-to-peer secret replication over the Akka cluster.
/// </summary>
public sealed class AkkaSecretsReplicationOptions
{
    /// <summary>
    /// How often this node broadcasts its manifest for anti-entropy. Defaults to 30 seconds.
    /// </summary>
    /// <remarks>
    /// This is the convergence bound, not the propagation latency: a live write reaches peers in
    /// milliseconds, and this interval only governs how quickly a <em>dropped</em> write or a
    /// rejoining node is repaired. The traffic is one manifest per node per interval — names,
    /// revisions, and timestamps, no ciphertext — so shortening it is cheap for a small cluster and
    /// grows as O(nodes × secrets).
    /// </remarks>
    public TimeSpan AnnounceInterval { get; set; } = TimeSpan.FromSeconds(30);

    /// <summary>Name of the replication actor within the actor system. Defaults to <c>zb-secret-replication</c>.</summary>
    public string ActorName { get; set; } = "zb-secret-replication";

    /// <summary>
    /// Throws if the options are unusable.
    /// </summary>
    /// <exception cref="InvalidOperationException">The announce interval is not positive, or the actor name is blank.</exception>
    public void Validate()
    {
        if (AnnounceInterval <= TimeSpan.Zero)
        {
            throw new InvalidOperationException(
                $"Secret replication AnnounceInterval must be positive (was {AnnounceInterval}).");
        }

        if (string.IsNullOrWhiteSpace(ActorName))
        {
            throw new InvalidOperationException("Secret replication ActorName must not be blank.");
        }
    }
}
