/**
 * Resilience utilities for protecting against external service failures.
 *
 * This module provides:
 * - Timeout wrappers for external service calls
 * - Circuit breaker pattern for preventing cascading failures
 * - Infrastructure error types for proper error classification
 * - Rate limiting (token bucket algorithm)
 * - Retry with exponential backoff
 * - HTTP error mapping
 *
 * @example
 * ```typescript
 * import {
 *   withTimeout,
 *   SERVICE_TIMEOUTS,
 *   createCircuitBreaker,
 *   ServiceTimeoutError,
 *   ServiceUnavailableError,
 *   isInfrastructureError,
 *   withRetry,
 *   DEFAULT_RETRY_POLICY,
 *   createRateLimiter,
 *   createHttpError
 * } from '@repo/core/resilience'
 *
 * // Wrap external calls with timeout
 * const result = await withTimeout(
 *   externalService.call(),
 *   SERVICE_TIMEOUTS.WORKOS_JWT,
 *   'ServiceName',
 *   'operation'
 * )
 *
 * // Use circuit breaker for services with repeated failures
 * const breaker = createCircuitBreaker('my-service')
 * const data = await breaker.execute(() => myService.fetch())
 *
 * // Use retry with exponential backoff
 * const response = await withRetry(
 *   () => fetch('/api/data'),
 *   DEFAULT_RETRY_POLICY
 * )
 * ```
 */

// Error types
export {
  ServiceTimeoutError,
  ServiceUnavailableError,
  isInfrastructureError
} from './errors'

// Timeout utility
export { withTimeout, SERVICE_TIMEOUTS } from './timeout'

// Circuit breaker
export {
  createCircuitBreaker,
  CircuitState,
  type CircuitBreaker,
  type CircuitBreakerConfig
} from './circuit-breaker'

// Rate limiting
export {
  InMemoryRateLimiter,
  createRateLimiter
} from './rate-limiter'

// Retry logic
export {
  withRetry,
  calculateRetryDelay,
  sleep
} from './retry'

// Rate limiter types
export {
  type RateLimiter,
  type RetryPolicy
} from './rate-limiter-types'

// Retry policy constant (canonical source: constants/resilience)
export { DEFAULT_RETRY_POLICY } from '../constants/resilience'

// HTTP error mapping
export {
  createHttpError,
  mapHttpStatusToErrorType,
  type HttpErrorContext,
  type ErrorParser
} from './http-error-mapper'
