/**
 * Retry Policy
 * Configurable retry strategies for observability exporters
 */
import type { RetryPolicy } from "../types/observability.js";
/**
 * Result of a retry decision
 */
export type RetryDecision = {
    /** Whether to retry */
    shouldRetry: boolean;
    /** Delay before retry in milliseconds */
    delayMs: number;
    /** Reason for the decision */
    reason: string;
};
/**
 * Context for retry decision making
 */
export type RetryContext = {
    /** Current attempt number (0-indexed) */
    attempt: number;
    /** The error that triggered the retry */
    error: Error;
    /** Total elapsed time since first attempt */
    elapsedMs: number;
    /** Operation name for logging */
    operationName: string;
    /** Additional metadata */
    metadata?: Record<string, unknown>;
};
export type { RetryPolicy };
/**
 * Base retry policy with common configuration
 */
export declare abstract class BaseRetryPolicy implements RetryPolicy {
    abstract readonly name: string;
    readonly maxAttempts: number;
    readonly maxTotalTimeMs: number;
    protected readonly retryableErrors: Set<string>;
    protected readonly nonRetryableErrors: Set<string>;
    constructor(config: {
        maxAttempts?: number;
        maxTotalTimeMs?: number;
        retryableErrors?: string[];
        nonRetryableErrors?: string[];
    });
    abstract shouldRetry(context: RetryContext): RetryDecision;
    protected isRetryableError(error: Error): boolean;
    protected extractErrorCode(error: Error): string;
}
/**
 * Exponential backoff retry policy
 * Delay increases exponentially with each attempt
 */
export declare class ExponentialBackoffPolicy extends BaseRetryPolicy {
    readonly name = "exponential-backoff";
    private readonly baseDelayMs;
    private readonly maxDelayMs;
    private readonly jitterFactor;
    constructor(config?: {
        maxAttempts?: number;
        maxTotalTimeMs?: number;
        baseDelayMs?: number;
        maxDelayMs?: number;
        jitterFactor?: number;
        retryableErrors?: string[];
        nonRetryableErrors?: string[];
    });
    shouldRetry(context: RetryContext): RetryDecision;
}
/**
 * Linear backoff retry policy
 * Delay increases linearly with each attempt
 */
export declare class LinearBackoffPolicy extends BaseRetryPolicy {
    readonly name = "linear-backoff";
    private readonly delayIncrementMs;
    private readonly initialDelayMs;
    constructor(config?: {
        maxAttempts?: number;
        maxTotalTimeMs?: number;
        initialDelayMs?: number;
        delayIncrementMs?: number;
        retryableErrors?: string[];
        nonRetryableErrors?: string[];
    });
    shouldRetry(context: RetryContext): RetryDecision;
}
/**
 * Fixed delay retry policy
 * Same delay for all retry attempts
 */
export declare class FixedDelayPolicy extends BaseRetryPolicy {
    readonly name = "fixed-delay";
    private readonly delayMs;
    constructor(config?: {
        maxAttempts?: number;
        maxTotalTimeMs?: number;
        delayMs?: number;
        retryableErrors?: string[];
        nonRetryableErrors?: string[];
    });
    shouldRetry(context: RetryContext): RetryDecision;
}
/**
 * No retry policy - never retries
 */
export declare class NoRetryPolicy implements RetryPolicy {
    readonly name = "no-retry";
    readonly maxAttempts = 1;
    readonly maxTotalTimeMs = 0;
    shouldRetry(_context: RetryContext): RetryDecision;
}
/**
 * Circuit breaker aware retry policy
 * Works with circuit breaker state to prevent retries when circuit is open
 */
export declare class CircuitBreakerAwarePolicy extends BaseRetryPolicy {
    readonly name = "circuit-breaker-aware";
    private readonly innerPolicy;
    private failures;
    private lastFailure;
    private circuitState;
    private readonly failureThreshold;
    private readonly resetTimeoutMs;
    constructor(config?: {
        innerPolicy?: RetryPolicy;
        failureThreshold?: number;
        resetTimeoutMs?: number;
        maxAttempts?: number;
        maxTotalTimeMs?: number;
        retryableErrors?: string[];
        nonRetryableErrors?: string[];
    });
    shouldRetry(context: RetryContext): RetryDecision;
    recordFailure(): void;
    recordSuccess(): void;
    getCircuitState(): "closed" | "open" | "half-open";
    reset(): void;
}
/**
 * Retry executor - executes operations with retry policy
 */
export declare class RetryExecutor {
    private readonly policy;
    constructor(policy: RetryPolicy);
    /**
     * Execute an operation with retry
     * @param operation - The async operation to execute
     * @param operationName - Name for logging
     * @returns The result of the operation
     * @throws The last error if all retries fail
     */
    execute<T>(operation: () => Promise<T>, operationName: string): Promise<T>;
    private delay;
}
/**
 * Factory for creating retry policies
 */
export declare class RetryPolicyFactory {
    /**
     * Create a default policy for production use
     */
    static createDefault(): ExponentialBackoffPolicy;
    /**
     * Create an aggressive policy for critical operations
     */
    static createAggressive(): ExponentialBackoffPolicy;
    /**
     * Create a conservative policy for non-critical operations
     */
    static createConservative(): LinearBackoffPolicy;
    /**
     * Create a circuit breaker aware policy
     */
    static createWithCircuitBreaker(config?: {
        failureThreshold?: number;
        resetTimeoutMs?: number;
    }): CircuitBreakerAwarePolicy;
}
