/**
 * 🔧 UNIFIED Page Analysis Event System
 *
 * ✨ MAIN EVENT SYSTEM - Replaces multiple parallel event systems
 *
 * Event-driven system where analyzers attach to page load events
 * and contribute their data to a unified result structure.
 *
 * 🎯 CONSOLIDATES:
 * - AccessibilityChecker event callbacks
 * - EventDrivenQueue callbacks
 * - ParallelTestManager events
 * - Direct callback patterns in bin/audit.js
 *
 * 📋 BACKWARD COMPATIBILITY:
 * - Supports all existing callback patterns via adapters
 * - Maintains existing APIs while using unified backend
 *
 * 🚀 FEATURES:
 * - Parallel analyzer execution
 * - Resource monitoring integration
 * - Backpressure control integration
 * - Progress tracking
 * - Error handling & fallbacks
 * - State persistence
 */
import { EventEmitter } from 'events';
import { Page } from 'playwright';
import { AccessibilityResult, TestOptions } from '../../types';
export interface PageAnalysisContext {
    url: string;
    page: Page;
    options: TestOptions;
    result: PageAnalysisResult;
    startTime: number;
    retryCount?: number;
    maxRetries?: number;
    sessionId?: string;
    batchId?: string;
    priority?: number;
    memoryUsageMB?: number;
    cpuUsagePercent?: number;
    backpressureActive?: boolean;
}
/**
 * 🎯 UNIFIED Event Callbacks - Supports ALL existing callback patterns
 *
 * This interface consolidates all event patterns from:
 * - TestOptions.eventCallbacks
 * - EventDrivenQueueOptions.eventCallbacks
 * - ParallelTestManager callbacks
 * - bin/audit.js direct callbacks
 */
export interface UnifiedEventCallbacks {
    onUrlAdded?: (url: string, priority?: number) => void;
    onUrlStarted?: (url: string) => void;
    onUrlCompleted?: (url: string, result: AccessibilityResult, duration: number) => void;
    onUrlFailed?: (url: string, error: string, attempts: number) => void;
    onUrlRetrying?: (url: string, attempts: number) => void;
    onProgressUpdate?: (stats: ProgressStats) => void;
    onQueueEmpty?: () => void;
    onBatchComplete?: (results: PageAnalysisResult[]) => void;
    onError?: (error: string, context?: any) => void;
    onResourceWarning?: (usage: number, limit: number, type: 'memory' | 'cpu') => void;
    onResourceCritical?: (usage: number, limit: number, type: 'memory' | 'cpu') => void;
    onBackpressureActivated?: (reason: string) => void;
    onBackpressureDeactivated?: () => void;
    onGarbageCollection?: (beforeMB: number, afterMB?: number) => void;
    onAnalyzerStart?: (analyzerName: string, url: string) => void;
    onAnalyzerComplete?: (analyzerName: string, url: string, result: any) => void;
    onAnalyzerError?: (analyzerName: string, url: string, error: string) => void;
    onShortStatus?: (status: string) => void;
    onSystemMetrics?: (metrics: SystemMetrics) => void;
}
/**
 * 📈 Unified progress statistics
 */
export interface ProgressStats {
    total: number;
    pending: number;
    inProgress: number;
    completed: number;
    failed: number;
    retrying: number;
    progress: number;
    averageDuration: number;
    estimatedTimeRemaining: number;
    activeWorkers: number;
    memoryUsage: number;
    cpuUsage: number;
    batchId?: string;
    batchSize?: number;
    currentBatch?: number;
    totalBatches?: number;
}
/**
 * 🚀 System metrics for monitoring
 */
export interface SystemMetrics {
    memoryUsageMB: number;
    heapUsedMB: number;
    cpuUsagePercent: number;
    eventLoopDelayMs: number;
    activeHandles: number;
    gcCount: number;
    uptimeSeconds: number;
}
export interface PageAnalysisResult {
    url: string;
    title: string;
    status: 'success' | 'failed' | 'crashed';
    duration: number;
    accessibility: {
        passed: boolean;
        score: number;
        errors: Array<{
            code: string;
            message: string;
            type: 'error' | 'warning' | 'notice';
        }>;
        warnings: Array<{
            code: string;
            message: string;
            type: 'error' | 'warning' | 'notice';
        }>;
        issues: Array<{
            code: string;
            message: string;
            type: 'error' | 'warning' | 'notice';
            selector?: string;
            context?: string;
            impact?: string;
        }>;
        basicChecks: {
            imagesWithoutAlt: number;
            buttonsWithoutLabel: number;
            headingsCount: number;
        };
    };
    performance?: {
        score: number;
        grade: string;
        coreWebVitals: {
            lcp: number;
            fcp: number;
            cls: number;
            inp: number;
            ttfb: number;
        };
        timing: {
            loadTime: number;
            domContentLoaded: number;
            renderTime: number;
        };
    };
    seo?: {
        score: number;
        grade: string;
        metaTags: {
            title?: {
                content: string;
                length: number;
                optimal: boolean;
            };
            description?: {
                content: string;
                length: number;
                optimal: boolean;
            };
            keywords?: string[];
            openGraph: Record<string, any>;
            twitterCard: Record<string, any>;
        };
        headings: {
            h1: string[];
            h2: string[];
            h3: string[];
            issues: string[];
        };
        images: {
            total: number;
            missingAlt: number;
            emptyAlt: number;
        };
    };
    contentWeight?: {
        score: number;
        grade: string;
        totalSize: number;
        resources: {
            html: {
                size: number;
            };
            css: {
                size: number;
                files: number;
            };
            javascript: {
                size: number;
                files: number;
            };
            images: {
                size: number;
                files: number;
            };
            other: {
                size: number;
                files: number;
            };
        };
        optimizations: string[];
    };
    mobileFriendliness?: {
        score: number;
        grade: string;
        viewport: {
            hasViewportMeta: boolean;
            width?: string;
            initialScale?: number;
        };
        touchTargets: {
            tooSmall: number;
            overlapping: number;
        };
        textReadability: {
            tooSmall: number;
        };
        contentFit: {
            horizontalScrolling: boolean;
        };
    };
}
/**
 * 🎯 UNIFIED PAGE ANALYSIS EMITTER - Main Event System
 *
 * Replaces multiple parallel event systems with a single, comprehensive solution.
 * Maintains backward compatibility while providing enhanced features.
 */
export declare class PageAnalysisEmitter extends EventEmitter {
    private analyzers;
    private callbacks;
    private backpressureController?;
    private resourceMonitor?;
    private stats;
    private systemMetrics;
    private sessionId;
    private isInitialized;
    private options;
    constructor(options?: Partial<{
        enableResourceMonitoring: boolean;
        enableBackpressure: boolean;
        maxConcurrent: number;
        maxRetries: number;
        retryDelay: number;
        verbose: boolean;
        callbacks: UnifiedEventCallbacks;
    }>);
    /**
     * 🚀 Initialize the unified event system with integrated monitoring
     */
    initialize(): Promise<void>;
    /**
     * 📋 Register an analyzer that will run when a page is loaded
     *
     * BACKWARD COMPATIBLE: Maintains existing analyzer registration pattern
     */
    registerAnalyzer(name: string, analyzer: AnalyzerFunction): void;
    /**
     * 🎯 Set unified event callbacks
     *
     * This replaces/consolidates:
     * - TestOptions.eventCallbacks
     * - EventDrivenQueueOptions.eventCallbacks
     * - Direct callback patterns
     */
    setEventCallbacks(callbacks: UnifiedEventCallbacks): void;
    /**
     * 📊 Setup resource monitoring integration
     */
    private setupResourceMonitoring;
    /**
     * 🏃 Setup backpressure control integration
     */
    private setupBackpressureControl;
    /**
     * 📈 Update and emit progress statistics
     */
    private updateProgress;
    /**
     * 🎯 Get current progress statistics
     */
    getProgressStats(): ProgressStats;
    /**
     * 🚀 Get system metrics
     */
    getSystemMetrics(): SystemMetrics;
    /**
     * 🧪 Cleanup resources (enhanced version)
     */
    cleanup(): Promise<void>;
    /**
     * 🎯 UNIFIED PAGE ANALYSIS - Enhanced version with all features
     *
     * BACKWARD COMPATIBLE: Maintains existing analyzePage signature
     * ENHANCED: Integrates resource monitoring, backpressure, progress tracking
     */
    analyzePage(url: string, page: Page, options?: TestOptions, contextOptions?: Partial<PageAnalysisContext>): Promise<PageAnalysisResult>;
    /**
     * Get list of registered analyzers
     */
    getRegisteredAnalyzers(): string[];
}
export type AnalyzerFunction = (context: PageAnalysisContext) => Promise<void>;
export declare const accessibilityAnalyzer: AnalyzerFunction;
export declare const performanceAnalyzer: AnalyzerFunction;
export declare const seoAnalyzer: AnalyzerFunction;
//# sourceMappingURL=page-analysis-emitter.d.ts.map