/**
 * Okta-specific Circuit Breaker implementation with smart retry logic
 * Simplified version that handles errors correctly
 */
import { CircuitState, CircuitBreakerStats, ICircuitBreaker, ICircuitBreakerEventEmitter } from './types.js';
import { ICache } from '../cache/interface.js';
/**
 * Okta-specific error codes and their handling strategies
 */
export declare enum OktaErrorCode {
    RATE_LIMIT = 429,
    BAD_GATEWAY = 502,
    SERVICE_UNAVAILABLE = 503,
    GATEWAY_TIMEOUT = 504,
    UNAUTHORIZED = 401,
    FORBIDDEN = 403,
    NOT_FOUND = 404,
    OK = 200,
    CREATED = 201,
    NO_CONTENT = 204
}
/**
 * Okta API error interface
 */
export interface OktaApiError extends Error {
    status?: number;
    code?: string;
    errorCode?: string;
    errorSummary?: string;
    errorLink?: string;
    errorId?: string;
    headers?: {
        'x-rate-limit-limit'?: string;
        'x-rate-limit-remaining'?: string;
        'x-rate-limit-reset'?: string;
        'retry-after'?: string;
    };
}
/**
 * Okta circuit breaker configuration
 */
export interface OktaCircuitBreakerOptions {
    /**
     * Number of failures before opening the circuit
     */
    failureThreshold: number;
    /**
     * Time in milliseconds before attempting to close the circuit
     */
    resetTimeout: number;
    /**
     * Request timeout in milliseconds
     */
    timeout?: number;
    /**
     * Name for the circuit breaker
     */
    name?: string;
    /**
     * Cache instance for fallback on read operations
     */
    cache?: ICache;
    /**
     * Cache TTL in milliseconds
     */
    cacheTTL?: number;
    /**
     * Enable cache fallback for read operations
     * @default true
     */
    enableCacheFallback?: boolean;
    /**
     * Maximum retry attempts for rate limit errors
     * @default 3
     */
    maxRetries?: number;
    /**
     * Initial retry delay in milliseconds
     * @default 1000
     */
    initialRetryDelay?: number;
    /**
     * Maximum retry delay in milliseconds
     * @default 30000
     */
    maxRetryDelay?: number;
    /**
     * Retry delay multiplier for exponential backoff
     * @default 2
     */
    retryMultiplier?: number;
    /**
     * Whether to use jitter in retry delays
     * @default true
     */
    useJitter?: boolean;
}
/**
 * Simple Okta-specific circuit breaker implementation
 */
export declare class OktaCircuitBreaker<T = any> implements ICircuitBreaker<T> {
    private state;
    private failures;
    private lastFailureTime?;
    private nextAttempt;
    private readonly cache?;
    private readonly options;
    private readonly eventEmitter;
    private totalRequests;
    private totalFailures;
    private totalSuccesses;
    private totalRejections;
    constructor(options: OktaCircuitBreakerOptions);
    /**
     * Execute a function with Okta-specific retry logic
     */
    execute<R>(fn: (...args: T[]) => Promise<R>, ...args: T[]): Promise<R>;
    /**
     * Execute with exponential backoff retry for rate limits
     */
    private executeWithRetry;
    /**
     * Record a successful execution
     */
    private recordSuccess;
    /**
     * Record a failed execution
     */
    private recordFailure;
    /**
     * Transition to a new state
     */
    private transitionTo;
    /**
     * Determine if an error should count as a circuit breaker failure
     */
    private isOktaFailure;
    /**
     * Check if error is a rate limit error
     */
    private isRateLimitError;
    /**
     * Check if error is a network error
     */
    private isNetworkError;
    /**
     * Calculate retry delay with exponential backoff and jitter
     */
    private calculateRetryDelay;
    /**
     * Cache fallback for read operations
     */
    private cacheFallback;
    /**
     * Sleep for specified milliseconds
     */
    private sleep;
    getState(): CircuitState;
    getStats(): CircuitBreakerStats;
    open(): void;
    close(): void;
    reset(): void;
    isOpen(): boolean;
    getEventEmitter(): ICircuitBreakerEventEmitter;
    healthCheck(): Promise<CircuitBreakerStats>;
}
/**
 * Factory function to create an Okta circuit breaker
 */
export declare function createOktaCircuitBreaker<T = any>(options: OktaCircuitBreakerOptions): ICircuitBreaker<T>;
/**
 * Wrapper function to wrap any async function with Okta circuit breaker
 */
export declare function withOktaCircuitBreaker<T extends (...args: any[]) => Promise<any>>(fn: T, options?: Partial<OktaCircuitBreakerOptions>): T;
/**
 * Higher-order function to create a cached Okta API method
 */
export declare function createCachedOktaMethod<T extends (...args: any[]) => Promise<any>>(method: T, cache: ICache, options?: Partial<OktaCircuitBreakerOptions>): T;
//# sourceMappingURL=okta-circuit-breaker.d.ts.map