/**
 * Playbook Executor - Automated Incident Response Execution
 *
 * State machine for playbook execution with:
 * - Step execution with timeout handling
 * - Retry logic for failed steps
 * - Rollback capability for failed playbooks
 * - Parallel step execution where dependencies allow
 * - Persistent state tracking
 *
 * @packageDocumentation
 * @module security/incident/executor
 */
import { EventEmitter } from 'events';
import { Incident, Playbook, PlaybookExecutionState, ActionDefinition, Evidence, UpdateIncidentInput, ExecutionStateStore, StepExecutionResult } from './types.js';
export interface PlaybookExecutorConfig {
    /** Maximum concurrent step executions */
    maxConcurrentSteps: number;
    /** Default step timeout in milliseconds */
    defaultStepTimeoutMs: number;
    /** Whether to enable automatic rollback on failure */
    enableAutoRollback: boolean;
    /** Maximum retry delay multiplier for exponential backoff */
    maxRetryBackoffMultiplier: number;
    /** Base retry delay in milliseconds */
    baseRetryDelayMs: number;
    /** State storage for persistence */
    stateStore?: ExecutionStateStore;
    /** Whether to persist state */
    persistState: boolean;
}
declare class InMemoryStateStore implements ExecutionStateStore {
    private states;
    private incidentIndex;
    save(state: PlaybookExecutionState): Promise<void>;
    load(executionId: string): Promise<PlaybookExecutionState | null>;
    loadByIncident(incidentId: string): Promise<PlaybookExecutionState | null>;
    delete(executionId: string): Promise<void>;
    listActive(): Promise<PlaybookExecutionState[]>;
    update(executionId: string, updates: Partial<PlaybookExecutionState>): Promise<void>;
}
export interface ExecutorEvents {
    'execution:started': (state: PlaybookExecutionState) => void;
    'execution:completed': (state: PlaybookExecutionState) => void;
    'execution:failed': (state: PlaybookExecutionState, error: string) => void;
    'execution:paused': (state: PlaybookExecutionState, reason: string) => void;
    'execution:resumed': (state: PlaybookExecutionState) => void;
    'execution:cancelled': (state: PlaybookExecutionState) => void;
    'execution:rolledBack': (state: PlaybookExecutionState) => void;
    'step:started': (executionId: string, stepId: string) => void;
    'step:completed': (executionId: string, stepId: string, result: StepExecutionResult) => void;
    'step:failed': (executionId: string, stepId: string, error: string) => void;
    'step:waiting': (executionId: string, stepId: string, reason: 'approval' | 'manual') => void;
    'step:approved': (executionId: string, stepId: string, approver: string) => void;
    'step:rolledBack': (executionId: string, stepId: string) => void;
}
export declare class PlaybookExecutor extends EventEmitter {
    private readonly config;
    private readonly stateStore;
    private readonly actions;
    private readonly activeExecutions;
    private incidentUpdater?;
    private evidenceAdder?;
    constructor(config?: Partial<PlaybookExecutorConfig>);
    /**
     * Register handlers for incident updates and evidence
     */
    registerHandlers(handlers: {
        updateIncident: (incidentId: string, updates: UpdateIncidentInput) => Promise<void>;
        addEvidence: (incidentId: string, evidence: Omit<Evidence, 'id' | 'collectedAt'>) => Promise<Evidence>;
    }): void;
    /**
     * Register an action definition
     */
    registerAction(action: ActionDefinition): void;
    /**
     * Get a registered action
     */
    getAction(actionId: string): ActionDefinition | undefined;
    /**
     * Start executing a playbook for an incident
     */
    startExecution(incident: Incident, playbook: Playbook): Promise<PlaybookExecutionState>;
    /**
     * Resume a paused execution
     */
    resumeExecution(executionId: string, incident: Incident, playbook: Playbook): Promise<void>;
    /**
     * Cancel an active execution
     */
    cancelExecution(executionId: string): Promise<void>;
    /**
     * Approve a step that requires approval
     */
    approveStep(executionId: string, stepId: string, approver: string): Promise<void>;
    /**
     * Mark a manual step as completed
     */
    completeManualStep(executionId: string, stepId: string, completedBy: string, output?: unknown): Promise<void>;
    /**
     * Rollback a failed execution
     */
    rollbackExecution(executionId: string, incident: Incident, playbook: Playbook): Promise<void>;
    /**
     * Get execution state
     */
    getExecutionState(executionId: string): Promise<PlaybookExecutionState | null>;
    /**
     * Get execution state by incident
     */
    getExecutionByIncident(incidentId: string): Promise<PlaybookExecutionState | null>;
    /**
     * Get all active executions
     */
    getActiveExecutions(): Promise<PlaybookExecutionState[]>;
    private runExecution;
    private findExecutableSteps;
    private executeStep;
    private executeWithTimeout;
    private calculateRetryDelay;
    private createActionContext;
    private isActiveState;
    private sleep;
}
export declare function createPlaybookExecutor(config?: Partial<PlaybookExecutorConfig>): PlaybookExecutor;
export { InMemoryStateStore };
export type { ExecutionStateStore };
//# sourceMappingURL=executor.d.ts.map