///|
/// Retry behaviour for session round trips. Only transport-level failures
/// (broken connection, premature close) trigger a retry; protocol results
/// are never retried. `backoff_ms` is the wait between attempts (0 keeps
/// tests and offline usage fully deterministic).
pub struct RetryPolicy {
  max_retries : Int
  backoff_ms : Int
} derive(Eq, @debug.Debug)

///|
pub fn RetryPolicy::new(max_retries? : Int, backoff_ms? : Int) -> RetryPolicy {
  {
    max_retries: match max_retries {
      Some(v) => v
      None => 0
    },
    backoff_ms: match backoff_ms {
      Some(v) => v
      None => 0
    },
  }
}

///|
/// Configure retry behaviour for all subsequent operations on this session.
pub fn[T] Session::set_retry(self : Session[T], policy : RetryPolicy) -> Unit {
  self.retry = Some(policy)
}

///|
/// Configure retry behaviour on the client's underlying session.
pub fn[T] LdapClient::set_retry(
  self : LdapClient[T],
  policy : RetryPolicy,
) -> Unit {
  self.session.set_retry(policy)
}