/**
 * Circuit Breaker Pattern Implementation
 * Prevents cascading failures and enables graceful degradation
 */
import { EventEmitter } from 'events';
export declare enum CircuitState {
    CLOSED = "closed",// Normal operation
    OPEN = "open",// Failing, blocking requests
    HALF_OPEN = "half-open"
}
export interface CircuitBreakerOptions {
    failureThreshold?: number;
    resetTimeout?: number;
    monitoringPeriod?: number;
    successThreshold?: number;
    timeoutMs?: number;
    volumeThreshold?: number;
}
export interface CircuitBreakerMetrics {
    state: CircuitState;
    failureCount: number;
    successCount: number;
    totalCalls: number;
    lastFailureTime: number;
    lastSuccessTime: number;
    stateChangeTime: number;
    failureRate: number;
}
export declare class CircuitBreaker<T extends (...args: any[]) => Promise<any>> extends EventEmitter {
    private state;
    private failureCount;
    private successCount;
    private totalCalls;
    private lastFailureTime;
    private lastSuccessTime;
    private stateChangeTime;
    private recentCalls;
    private resetTimer?;
    private readonly options;
    private readonly operation;
    private readonly name;
    constructor(operation: T, name: string, options?: CircuitBreakerOptions);
    /**
     * Execute the wrapped operation with circuit breaker protection
     */
    execute(...args: Parameters<T>): Promise<ReturnType<T>>;
    /**
     * Execute operation with timeout
     */
    private executeWithTimeout;
    /**
     * Handle successful execution
     */
    private onSuccess;
    /**
     * Handle failed execution
     */
    private onFailure;
    /**
     * Determine if circuit should open based on failure criteria
     */
    private shouldOpenCircuit;
    /**
     * Transition circuit to new state
     */
    private transitionTo;
    /**
     * Schedule transition to half-open state
     */
    private scheduleReset;
    /**
     * Reset circuit breaker metrics
     */
    private reset;
    /**
     * Clean up old call records outside monitoring period
     */
    private cleanupOldCalls;
    /**
     * Force circuit to specific state (for testing/recovery)
     */
    forceState(state: CircuitState): void;
    /**
     * Get current circuit breaker metrics
     */
    getMetrics(): CircuitBreakerMetrics;
    /**
     * Check if circuit is available for requests
     */
    isAvailable(): boolean;
    /**
     * Get current state
     */
    getState(): CircuitState;
    /**
     * Shutdown circuit breaker
     */
    shutdown(): void;
}
/**
 * Circuit breaker specific error types
 */
export declare class CircuitBreakerOpenError extends Error {
    constructor(message: string);
}
export declare class CircuitBreakerTimeoutError extends Error {
    constructor(message: string);
}
/**
 * Circuit breaker manager for multiple operations
 */
export declare class CircuitBreakerManager extends EventEmitter {
    private breakers;
    /**
     * Create or get circuit breaker for operation
     */
    getCircuitBreaker<T extends (...args: any[]) => Promise<any>>(name: string, operation: T, options?: CircuitBreakerOptions): CircuitBreaker<T>;
    /**
     * Get all circuit breaker metrics
     */
    getAllMetrics(): {
        [name: string]: CircuitBreakerMetrics;
    };
    /**
     * Get overall system health
     */
    getSystemHealth(): {
        totalBreakers: number;
        openBreakers: number;
        halfOpenBreakers: number;
        closedBreakers: number;
        overallHealth: number;
    };
    /**
     * Force all circuits to closed state (emergency recovery)
     */
    forceAllClosed(): void;
    /**
     * Shutdown all circuit breakers
     */
    shutdown(): void;
}
export declare function getGlobalCircuitBreakerManager(): CircuitBreakerManager;
export declare function shutdownGlobalCircuitBreakerManager(): void;
//# sourceMappingURL=circuit-breaker.d.ts.map