/**
 * Circuit Breaker pattern implementation
 *
 * Prevents cascading failures by temporarily blocking requests
 * to a failing service until it recovers.
 *
 * States:
 * - CLOSED: Normal operation, requests pass through
 * - OPEN: Failing, requests are blocked
 * - HALF_OPEN: Testing if service has recovered
 */
import { EventEmitter } from 'events';
export type CircuitState = 'CLOSED' | 'OPEN' | 'HALF_OPEN';
export interface CircuitBreakerOptions {
    /** Number of failures before opening circuit (default: 5) */
    failureThreshold?: number;
    /** Time in ms before attempting recovery (default: 30000) */
    resetTimeout?: number;
    /** Number of successful calls in HALF_OPEN to close circuit (default: 2) */
    successThreshold?: number;
    /** Time window in ms for failure counting (default: 60000) */
    failureWindow?: number;
    /** Function to determine if error should trip the breaker */
    isFailure?: (error: unknown) => boolean;
    /** Called when circuit state changes */
    onStateChange?: (from: CircuitState, to: CircuitState) => void;
}
export interface CircuitBreakerStats {
    state: CircuitState;
    failures: number;
    successes: number;
    consecutiveSuccesses: number;
    lastFailure: Date | null;
    lastSuccess: Date | null;
    totalRequests: number;
    failedRequests: number;
}
/**
 * Circuit Breaker implementation
 */
export declare class CircuitBreaker extends EventEmitter {
    private options;
    private onStateChange?;
    private state;
    private failures;
    private consecutiveSuccesses;
    private lastFailure;
    private lastSuccess;
    private nextAttempt;
    private totalRequests;
    private failedRequests;
    constructor(options?: CircuitBreakerOptions);
    /**
     * Execute a function through the circuit breaker
     */
    execute<T>(fn: () => Promise<T>): Promise<T>;
    /**
     * Check if request can be executed
     */
    private canExecute;
    /**
     * Handle successful execution
     */
    private onSuccess;
    /**
     * Handle failed execution
     */
    private onFailure;
    /**
     * Transition to a new state
     */
    private transitionTo;
    /**
     * Get current state
     */
    getState(): CircuitState;
    /**
     * Get circuit breaker statistics
     */
    getStats(): CircuitBreakerStats;
    /**
     * Manually reset the circuit breaker
     */
    reset(): void;
    /**
     * Manually trip the circuit breaker
     */
    trip(): void;
    /**
     * Check if circuit is healthy
     */
    isHealthy(): boolean;
    /**
     * Get time until next retry attempt (for OPEN state)
     */
    getTimeUntilRetry(): number;
    /**
     * Format stats for display
     */
    formatStats(): string;
    /**
     * Dispose and cleanup
     */
    dispose(): void;
}
/**
 * Get or create a named circuit breaker
 */
export declare function getCircuitBreaker(name: string, options?: CircuitBreakerOptions): CircuitBreaker;
/**
 * Get all circuit breaker stats
 */
export declare function getAllCircuitBreakerStats(): Record<string, CircuitBreakerStats>;
/**
 * Reset all circuit breakers
 */
export declare function resetAllCircuitBreakers(): void;
