import { IKosDataModel } from '../kosModel';
import { IKosTopicHandlerParams } from './kosTopicHandler';

/**
 * Advanced flow control options for kosTopicHandler
 */
export interface FlowControlOptions<T = any, R = T> {
    /**
     * Batching configuration
     */
    batch?: {
        /** Maximum number of events in a batch */
        size?: number;
        /** Maximum time window to collect events (ms) */
        window?: number;
    };
    /**
     * Transform function to apply to batched events
     * @param events - Array of events in the batch
     * @returns Transformed data to pass to handler
     */
    transform?: (events: T[]) => R;
    /**
     * Backpressure control to prevent overwhelming slow handlers
     */
    backpressure?: {
        /** Maximum concurrent handler executions */
        maxConcurrent?: number;
        /** Queue size limit before dropping events */
        maxQueue?: number;
        /** Policy for dropping events when queue is full */
        dropPolicy?: "oldest" | "newest" | "none";
        /** Callback when events are dropped due to queue overflow */
        onQueueFull?: (droppedEvents: T[]) => void;
    };
    /**
     * Advanced filtering with state awareness
     */
    filter?: {
        /** Predicate function for filtering events */
        predicate: (event: T, context: FilterContext) => boolean;
        /** Remember last N events for stateful filtering */
        historySize?: number;
    };
    /**
     * Rate limiting options
     */
    rateLimit?: {
        /** Maximum events to process per time window */
        maxEvents: number;
        /** Time window in milliseconds */
        windowMs: number;
        /** What to do when rate limit is exceeded */
        onExceeded?: "drop" | "delay" | "error";
    };
    /**
     * Error handling strategy for the flow
     */
    errorHandling?: {
        /** Retry failed events */
        retry?: {
            attempts: number;
            backoffMs: number;
        };
        /** Continue processing other events if one fails */
        continueOnError?: boolean;
    };
}
export interface FilterContext {
    /** Previous events in the filter history */
    history: any[];
    /** Current batch being processed */
    currentBatch: any[];
    /** Timestamp when filtering started */
    startTime: number;
}
/**
 * Enhanced kosTopicHandler params with flow control
 */
export interface IKosTopicHandlerFlowParams<T = any, Model extends IKosDataModel = any, R = T> extends IKosTopicHandlerParams<T, Model, R> {
    /**
     * Advanced flow control options using async iterators internally
     */
    flow?: FlowControlOptions<T, R>;
}
/**
 * Statistics for monitoring flow control performance
 */
export interface FlowControlStats {
    /** Total events received */
    eventsReceived: number;
    /** Total batches processed */
    batchesProcessed: number;
    /** Events dropped due to backpressure */
    eventsDropped: number;
    /** Current queue size */
    currentQueueSize: number;
    /** Average batch size */
    averageBatchSize: number;
    /** Processing rate (events/second) */
    processingRate: number;
    /** Last processing timestamp */
    lastProcessedAt: number;
}
/**
 * Internal flow control manager
 */
export declare class FlowControlManager<T = any, R = T> {
    private config;
    private stats;
    private filterHistory;
    private activePromises;
    private eventQueue;
    private rateLimitWindow;
    constructor(config: FlowControlOptions<T, R>);
    processEvents(eventStream: AsyncIterable<T>): AsyncGenerator<R, void, unknown>;
    private processSingleEvent;
    private processBatchedEvents;
    private shouldProcessEvent;
    private checkRateLimit;
    private waitForRateLimit;
    private waitForCapacity;
    private handleQueueOverflow;
    private enqueueEvent;
    private dequeueEvent;
    private updateProcessingStats;
    trackPromise<U>(promise: Promise<U>): Promise<U>;
    getStats(): FlowControlStats;
}
//# sourceMappingURL=kos-topic-handler-flow-control.d.ts.map