/**
 * Error Recovery Strategies
 *
 * This module provides error recovery strategies for handling infrastructure errors.
 * Strategies include retry with exponential backoff and rollback for transaction failures.
 *
 * @module declarative-api/errors/recovery-strategies
 */
import type { IResourceEntity } from '../../../lib/runtime-web/types/declarative-api/resource.types';
import type { InfrastructureError, InfrastructureErrorCategory } from './infrastructure-error';
/**
 * Result of a recovery attempt.
 */
export type RecoveryResult = RecoveryResultRecovered | RecoveryResultRetry | RecoveryResultRollback | RecoveryResultFail;
/**
 * Recovery succeeded and optionally produced a resource.
 */
export interface RecoveryResultRecovered {
    readonly type: 'recovered';
    readonly resource?: IResourceEntity;
    readonly message?: string;
}
/**
 * Recovery suggests retrying after a delay.
 */
export interface RecoveryResultRetry {
    readonly type: 'retry';
    readonly delayMs: number;
    readonly retryCount: number;
    readonly maxRetries: number;
}
/**
 * Recovery suggests rolling back all changes.
 */
export interface RecoveryResultRollback {
    readonly type: 'rollback';
    readonly reason: string;
}
/**
 * Recovery failed and the error should be propagated.
 */
export interface RecoveryResultFail {
    readonly type: 'fail';
    readonly error: InfrastructureError;
    readonly reason: string;
}
/**
 * Context provided to recovery strategies.
 */
export interface RecoveryContext {
    /** Current retry count for this error */
    readonly retryCount: number;
    /** Timestamp when the error first occurred */
    readonly firstErrorTime: Date;
    /** Additional metadata */
    readonly metadata?: Record<string, unknown>;
}
/**
 * Interface for error recovery strategies.
 *
 * Recovery strategies determine how to handle infrastructure errors,
 * whether to retry, rollback, or fail.
 *
 * Validates: Requirements 7.4
 */
export interface IErrorRecoveryStrategy {
    /** Strategy identifier */
    readonly strategyId: string;
    /**
     * Check if this strategy can handle the given error.
     *
     * @param error - The error to check
     * @returns True if this strategy can handle the error
     */
    canHandle(error: InfrastructureError): boolean;
    /**
     * Handle the error and determine recovery action.
     *
     * @param error - The error to handle
     * @param context - Recovery context with retry information
     * @returns The recovery result
     */
    handle(error: InfrastructureError, context: RecoveryContext): RecoveryResult;
}
/**
 * Options for RetryStrategy.
 */
export interface RetryStrategyOptions {
    /** Maximum number of retries (default: 3) */
    readonly maxRetries?: number;
    /** Base delay in milliseconds (default: 1000) */
    readonly baseDelayMs?: number;
    /** Maximum delay in milliseconds (default: 30000) */
    readonly maxDelayMs?: number;
    /** Jitter factor (0-1) to add randomness to delays (default: 0.1) */
    readonly jitterFactor?: number;
    /** Error codes that should trigger retry */
    readonly retryableCodes?: readonly string[];
    /** Error categories that should trigger retry */
    readonly retryableCategories?: readonly InfrastructureErrorCategory[];
}
/**
 * Retry strategy with exponential backoff.
 *
 * Retries failed operations with increasing delays between attempts.
 * Uses exponential backoff with optional jitter to prevent thundering herd.
 *
 * Validates: Requirements 7.4
 *
 * @example
 * ```typescript
 * const strategy = new RetryStrategy({
 *   maxRetries: 3,
 *   baseDelayMs: 1000,
 *   retryableCodes: ['COMMAND_EXECUTION_FAILED_ERROR'],
 * });
 *
 * if (strategy.canHandle(error)) {
 *   const result = strategy.handle(error, { retryCount: 0, firstErrorTime: new Date() });
 *   if (result.type === 'retry') {
 *     await sleep(result.delayMs);
 *     // Retry the operation
 *   }
 * }
 * ```
 */
export declare class RetryStrategy implements IErrorRecoveryStrategy {
    readonly strategyId = "retry-strategy";
    private readonly maxRetries;
    private readonly baseDelayMs;
    private readonly maxDelayMs;
    private readonly jitterFactor;
    private readonly retryableCodes;
    private readonly retryableCategories;
    constructor(options?: RetryStrategyOptions);
    /**
     * Check if this strategy can handle the given error.
     */
    canHandle(error: InfrastructureError): boolean;
    /**
     * Handle the error and determine recovery action.
     */
    handle(error: InfrastructureError, context: RecoveryContext): RecoveryResult;
    /**
     * Calculate delay with exponential backoff and jitter.
     */
    private calculateDelay;
}
/**
 * Options for RollbackStrategy.
 */
export interface RollbackStrategyOptions {
    /** Error codes that should trigger rollback */
    readonly rollbackCodes?: readonly string[];
    /** Error categories that should trigger rollback */
    readonly rollbackCategories?: readonly InfrastructureErrorCategory[];
}
/**
 * Rollback strategy for transaction failures.
 *
 * Triggers rollback of all changes when certain errors occur,
 * such as dependency resolution failures or circular dependencies.
 *
 * Validates: Requirements 7.4
 *
 * @example
 * ```typescript
 * const strategy = new RollbackStrategy();
 *
 * if (strategy.canHandle(error)) {
 *   const result = strategy.handle(error, context);
 *   if (result.type === 'rollback') {
 *     context.rollbackAll();
 *   }
 * }
 * ```
 */
export declare class RollbackStrategy implements IErrorRecoveryStrategy {
    readonly strategyId = "rollback-strategy";
    private readonly rollbackCodes;
    private readonly rollbackCategories;
    constructor(options?: RollbackStrategyOptions);
    /**
     * Check if this strategy can handle the given error.
     */
    canHandle(error: InfrastructureError): boolean;
    /**
     * Handle the error and determine recovery action.
     */
    handle(error: InfrastructureError, _context: RecoveryContext): RecoveryResult;
}
/**
 * Composite strategy that combines multiple recovery strategies.
 *
 * Tries each strategy in order until one can handle the error.
 */
export declare class CompositeRecoveryStrategy implements IErrorRecoveryStrategy {
    private readonly strategies;
    readonly strategyId = "composite-recovery-strategy";
    constructor(strategies: readonly IErrorRecoveryStrategy[]);
    /**
     * Check if any strategy can handle the given error.
     */
    canHandle(error: InfrastructureError): boolean;
    /**
     * Handle the error using the first matching strategy.
     */
    handle(error: InfrastructureError, context: RecoveryContext): RecoveryResult;
    /**
     * Add a strategy to the composite.
     */
    withStrategy(strategy: IErrorRecoveryStrategy): CompositeRecoveryStrategy;
}
/**
 * Create a default recovery strategy chain.
 *
 * The default chain tries retry first, then rollback.
 *
 * @param options - Options for the strategies
 * @returns A composite recovery strategy
 */
export declare function createDefaultRecoveryStrategy(options?: {
    retry?: RetryStrategyOptions;
    rollback?: RollbackStrategyOptions;
}): IErrorRecoveryStrategy;
/**
 * Type guard for RecoveryResultRecovered.
 */
export declare function isRecoveryResultRecovered(result: RecoveryResult): result is RecoveryResultRecovered;
/**
 * Type guard for RecoveryResultRetry.
 */
export declare function isRecoveryResultRetry(result: RecoveryResult): result is RecoveryResultRetry;
/**
 * Type guard for RecoveryResultRollback.
 */
export declare function isRecoveryResultRollback(result: RecoveryResult): result is RecoveryResultRollback;
/**
 * Type guard for RecoveryResultFail.
 */
export declare function isRecoveryResultFail(result: RecoveryResult): result is RecoveryResultFail;
