/**
 * Fallback and Error Handling System for Association Intelligence
 * Phase 3, Checkpoint C3 - Comprehensive error recovery and progress reporting
 */
import { LoadedAsset } from '../features/generation/assets/asset-loader';
import { DistributionTarget, DistributionAssignment, DistributionResult } from './distribution-algorithms';
import { EnforcementResult } from './constraint-enforcement';
export interface FallbackAsset extends LoadedAsset {
    fallbackType: 'synthetic' | 'template' | 'default';
    generatedBy: string;
    sourceTemplate?: string;
    fallbackReason: string;
    confidence: number;
}
export interface ErrorRecoveryOptions {
    enableFallbackGeneration: boolean;
    enableConstraintRelaxation: boolean;
    enablePartialFulfillment: boolean;
    maxRetryAttempts: number;
    fallbackStrategies: FallbackStrategy[];
    recoveryPriority: 'speed' | 'accuracy' | 'completeness';
    reportingLevel: 'minimal' | 'detailed' | 'verbose';
}
export interface FallbackStrategy {
    id: string;
    name: string;
    type: 'generate_synthetic' | 'use_template' | 'use_default' | 'duplicate_existing' | 'ai_generate';
    priority: number;
    applicableTypes: string[];
    generator: (requirements: FallbackRequirements) => Promise<FallbackAsset[]>;
    confidence: number;
    costWeight: number;
}
export interface FallbackRequirements {
    targetType: string;
    requiredCount: number;
    constraints?: Record<string, any>;
    existingAssets: LoadedAsset[];
    targetContext: DistributionTarget;
    templatePreferences?: string[];
}
export interface AssociationError {
    id: string;
    type: 'distribution_failure' | 'constraint_violation' | 'asset_insufficient' | 'validation_error' | 'system_error';
    severity: 'low' | 'medium' | 'high' | 'critical';
    message: string;
    context: {
        targetId?: string;
        assetIds?: string[];
        ruleName?: string;
        operation: string;
        timestamp: Date;
    };
    recoverable: boolean;
    suggestedActions: string[];
    metadata: Record<string, any>;
}
export interface RecoveryAttempt {
    attemptNumber: number;
    strategy: string;
    action: string;
    success: boolean;
    errorMessage?: string;
    recoveredItems: number;
    executionTime: number;
    confidence: number;
}
export interface ProgressReport {
    operationId: string;
    phase: 'initialization' | 'distribution' | 'constraint_enforcement' | 'error_recovery' | 'finalization';
    overallProgress: number;
    currentStep: string;
    completedSteps: string[];
    remainingSteps: string[];
    errors: AssociationError[];
    warnings: string[];
    statistics: {
        totalTargets: number;
        fulfilledTargets: number;
        totalAssets: number;
        assignedAssets: number;
        generatedFallbacks: number;
        recoveryAttempts: number;
        executionTime: number;
    };
    estimatedTimeRemaining?: number;
    canContinue: boolean;
}
export interface RecoveryResult {
    success: boolean;
    finalAssignments: DistributionAssignment[];
    recoveryAttempts: RecoveryAttempt[];
    generatedFallbacks: FallbackAsset[];
    unrecoverableErrors: AssociationError[];
    finalReport: ProgressReport;
    recommendations: string[];
    performanceMetrics: {
        totalRecoveryTime: number;
        fallbackGenerationTime: number;
        constraintRelaxationTime: number;
        finalValidationTime: number;
    };
}
export declare class FallbackErrorHandler {
    private fallbackStrategies;
    private options;
    private currentProgress;
    constructor(options: ErrorRecoveryOptions);
    /**
     * Handle insufficient assets by generating fallbacks
     */
    handleInsufficientAssets(target: DistributionTarget, currentAssets: LoadedAsset[], requiredCount: number): Promise<FallbackAsset[]>;
    /**
     * Attempt to recover from association errors
     */
    recoverFromErrors(distributionResult: DistributionResult, enforcementResult: EnforcementResult, originalAssets: LoadedAsset[]): Promise<RecoveryResult>;
    /**
     * Generate progress reports for long-running operations
     */
    reportProgress(): ProgressReport;
    /**
     * Update progress with new information
     */
    updateProgress(phase: ProgressReport['phase'], currentStep: string, progressIncrement?: number): void;
    /**
     * Attempt to recover from a specific error
     */
    private attemptErrorRecovery;
    /**
     * Recover from insufficient assets error
     */
    private recoverInsufficientAssets;
    /**
     * Recover from constraint violation
     */
    private recoverConstraintViolation;
    /**
     * Recover from distribution failure
     */
    private recoverDistributionFailure;
    /**
     * Check if an assignment is fulfilled based on its constraints
     */
    private checkFulfillment;
    /**
     * Analyze distribution and enforcement results to identify recoverable errors
     */
    private analyzeErrors;
    /**
     * Map constraint violation to error type
     */
    private mapViolationToErrorType;
    /**
     * Check if a violation is recoverable
     */
    private isViolationRecoverable;
    /**
     * Generate final recovery report
     */
    private generateFinalReport;
    /**
     * Generate recovery recommendations
     */
    private generateRecoveryRecommendations;
    /**
     * Infer the target type from constraints and existing assets
     */
    private inferTargetType;
    /**
     * Get template preferences for a target
     */
    private getTemplatePreferences;
    /**
     * Create initial progress report
     */
    private createInitialProgress;
    /**
     * Initialize built-in fallback strategies
     */
    private initializeBuiltInStrategies;
    /**
     * Add a custom fallback strategy
     */
    addFallbackStrategy(strategy: FallbackStrategy): void;
    /**
     * Remove a fallback strategy
     */
    removeFallbackStrategy(strategyId: string): boolean;
    /**
     * Get all available fallback strategies
     */
    getFallbackStrategies(): FallbackStrategy[];
    /**
     * Update error recovery options
     */
    updateOptions(newOptions: Partial<ErrorRecoveryOptions>): void;
    /**
     * Normalize asset type to ensure it's a valid LoadedAsset type
     */
    private normalizeAssetType;
    /**
     * Create a fallback error handler with default options
     */
    static createDefault(): FallbackErrorHandler;
}
//# sourceMappingURL=fallback-error-handling.d.ts.map