/**
 * Shared utility types for integration tools
 *
 * These types define the interfaces for rate limiting and retry logic
 * that are used by integration tools.
 */

/**
 * Rate limiter interface
 * Implements token bucket algorithm for rate limiting
 */
export interface RateLimiter {
  /**
   * Check if request is allowed
   * @param key - Rate limit key (e.g., '${organizationId}:${integration}')
   * @returns true if allowed, false if rate limited
   */
  allow(key: string): Promise<boolean>

  /**
   * Get remaining tokens for key
   * @param key - Rate limit key
   * @returns Number of tokens remaining
   */
  remaining(key: string): Promise<number>

  /**
   * Reset rate limit for key
   * @param key - Rate limit key
   */
  reset(key: string): Promise<void>
}

/**
 * Retry policy configuration
 */
export interface RetryPolicy {
  /** Maximum number of retry attempts */
  maxRetries: number
  /** Initial delay in ms (exponential backoff) */
  initialDelayMs: number
  /** Maximum delay in ms (cap for exponential backoff) */
  maxDelayMs: number
  /** Jitter factor (0-1, adds randomness to prevent thundering herd) */
  jitterFactor: number
}
