/**
 * Request Optimizer
 *
 * Optimizes API requests through:
 * - Request batching
 * - Deduplication of concurrent requests
 * - Retry with exponential backoff
 * - Request prioritization
 */
import { EventEmitter } from 'events';
export interface RequestConfig {
    /** Maximum concurrent requests */
    maxConcurrent: number;
    /** Batch window in ms */
    batchWindowMs: number;
    /** Maximum retries */
    maxRetries: number;
    /** Base delay for exponential backoff */
    retryBaseDelayMs: number;
    /** Request timeout */
    timeoutMs: number;
    /** Enable request deduplication */
    deduplicate: boolean;
}
export interface PendingRequest<T = unknown> {
    id: string;
    key: string;
    priority: number;
    execute: () => Promise<T>;
    resolve: (value: T) => void;
    reject: (error: Error) => void;
    retries: number;
    createdAt: number;
}
export interface RequestStats {
    totalRequests: number;
    successfulRequests: number;
    failedRequests: number;
    retriedRequests: number;
    deduplicatedRequests: number;
    averageLatency: number;
    currentConcurrency: number;
}
export declare class RequestOptimizer extends EventEmitter {
    private config;
    private queue;
    private running;
    private pendingDedup;
    private stats;
    private latencies;
    private batchTimeout;
    private processing;
    constructor(config?: Partial<RequestConfig>);
    /**
     * Execute a request with optimization
     */
    execute<T>(key: string, executeFn: () => Promise<T>, options?: {
        priority?: number;
        deduplicate?: boolean;
    }): Promise<T>;
    /**
     * Execute immediately without queuing
     */
    executeImmediate<T>(executeFn: () => Promise<T>, options?: {
        retries?: number;
        timeout?: number;
    }): Promise<T>;
    /**
     * Get current statistics
     */
    getStats(): RequestStats;
    /**
     * Reset statistics
     */
    resetStats(): void;
    /**
     * Clear pending requests
     */
    clear(): void;
    /**
     * Get queue status
     */
    getQueueStatus(): {
        pending: number;
        running: number;
        maxConcurrent: number;
    };
    private scheduleBatchProcess;
    private processQueue;
    private processRequest;
    private executeWithRetry;
    private withTimeout;
    private delay;
    private recordLatency;
}
export declare function getRequestOptimizer(config?: Partial<RequestConfig>): RequestOptimizer;
export declare function resetRequestOptimizer(): void;
/**
 * Execute multiple requests in parallel with concurrency limit
 */
export declare function executeParallel<T>(requests: Array<{
    key: string;
    execute: () => Promise<T>;
    priority?: number;
}>, options?: {
    maxConcurrent?: number;
}): Promise<Map<string, T | Error>>;
/**
 * Batch requests with automatic deduplication
 */
export declare function batchRequests<T, K extends string>(keys: K[], batchFn: (keys: K[]) => Promise<Map<K, T>>): Promise<Map<K, T>>;
