/**
 * Batch Messaging System
 * Aggregates multiple small messages into larger batches for efficient transmission.
 *
 * Features:
 * - Automatic batching of messages within a time window
 * - Configurable batch size and flush intervals
 * - Priority-based message ordering
 * - Compression for large payloads
 * - Statistics tracking
 */
export type MessagePriority = 'high' | 'normal' | 'low';
export interface QueuedMessage {
    type: string;
    data: Record<string, unknown>;
    priority: MessagePriority;
    timestamp: number;
}
export interface BatchedPayload {
    type: 'batch';
    messages: Array<{
        type: string;
        data: Record<string, unknown>;
    }>;
    count: number;
    timestamp: number;
}
export interface BatchStats {
    totalMessages: number;
    batchesSent: number;
    averageBatchSize: number;
    messagesDropped: number;
    bytesTransmitted: number;
    compressionRatio: number;
}
export interface BatchOptions {
    maxBatchSize?: number;
    flushIntervalMs?: number;
    maxQueueSize?: number;
    compressionThreshold?: number;
    onFlush?: (playerId: string, payload: BatchedPayload) => void;
}
/**
 * Batches messages for a single player/connection.
 * Messages are accumulated and flushed either when the batch size is reached
 * or when the flush interval elapses.
 */
export declare class MessageBatcher {
    private messageQueue;
    private maxBatchSize;
    private flushIntervalMs;
    private maxQueueSize;
    private compressionThreshold;
    private flushTimer;
    private onFlush;
    private totalMessages;
    private batchesSent;
    private messagesDropped;
    private bytesTransmitted;
    private uncompressedBytes;
    /**
     * Create a new message batcher.
     *
     * @param maxBatchSize - Max messages per batch (default: 50)
     * @param flushIntervalMs - Time before auto-flush (default: 100ms)
     * @param maxQueueSize - Max queued messages before dropping (default: 500)
     */
    constructor(options?: BatchOptions);
    /**
     * Set the flush callback.
     */
    setFlushCallback(callback: (payload: BatchedPayload) => void): void;
    /**
     * Queue a message for batching.
     *
     * @param type - Message type
     * @param data - Message payload
     * @param priority - Message priority (high messages are sent first)
     * @returns true if queued, false if dropped due to queue size
     */
    enqueue(type: string, data: Record<string, unknown>, priority?: MessagePriority): boolean;
    /**
     * Queue a high-priority message (flushes immediately).
     */
    enqueueHighPriority(type: string, data: Record<string, unknown>): boolean;
    /**
     * Flush all queued messages immediately.
     *
     * @returns The batched payload, or null if queue is empty
     */
    flush(): BatchedPayload | null;
    /**
     * Get the number of queued messages.
     */
    get queueSize(): number;
    /**
     * Get batcher statistics.
     */
    getStats(): BatchStats;
    /**
     * Reset statistics.
     */
    resetStats(): void;
    /**
     * Clear all queued messages without sending.
     */
    clear(): void;
    /**
     * Destroy the batcher, clearing all timers.
     */
    destroy(): void;
}
/**
 * Manages message batchers for multiple players.
 */
export declare class BatchMessageManager {
    private batchers;
    private options;
    private sendCallback;
    constructor(options?: BatchOptions);
    /**
     * Set the callback for sending batched messages.
     */
    setSendCallback(callback: (playerId: string, payload: BatchedPayload) => void): void;
    /**
     * Get or create a batcher for a player.
     */
    private getBatcher;
    /**
     * Queue a message for a player.
     */
    queueMessage(playerId: string, type: string, data: Record<string, unknown>, priority?: MessagePriority): boolean;
    /**
     * Queue a high-priority message for a player.
     */
    queueHighPriority(playerId: string, type: string, data: Record<string, unknown>): boolean;
    /**
     * Flush messages for a specific player.
     */
    flushPlayer(playerId: string): BatchedPayload | null;
    /**
     * Flush messages for all players.
     */
    flushAll(): Map<string, BatchedPayload>;
    /**
     * Remove a player's batcher (on disconnect).
     */
    removePlayer(playerId: string): void;
    /**
     * Get statistics for a player.
     */
    getPlayerStats(playerId: string): BatchStats | null;
    /**
     * Get aggregated statistics for all players.
     */
    getAllStats(): BatchStats;
    /**
     * Get the number of active batchers.
     */
    get playerCount(): number;
    /**
     * Clear all batchers.
     */
    clear(): void;
}
/**
 * Deduplicates messages within a batch.
 * For messages of the same type, keeps only the most recent one.
 */
export declare function deduplicateBatch(messages: Array<{
    type: string;
    data: Record<string, unknown>;
}>, deduplicateTypes?: string[]): Array<{
    type: string;
    data: Record<string, unknown>;
}>;
/**
 * Merges consecutive messages of the same type.
 * Useful for update messages where only the final state matters.
 */
export declare function mergeBatch(messages: Array<{
    type: string;
    data: Record<string, unknown>;
}>, mergeTypes?: string[]): Array<{
    type: string;
    data: Record<string, unknown>;
}>;
/**
 * Get the global batch message manager.
 */
export declare function getBatchMessageManager(options?: BatchOptions): BatchMessageManager;
/**
 * Send a message through the batching system.
 *
 * @param playerId - Player to send to
 * @param type - Message type
 * @param data - Message data
 * @param priority - Message priority
 */
export declare function sendBatchedMessage(playerId: string, type: string, data: Record<string, unknown>, priority?: MessagePriority): boolean;
/**
 * Send a high-priority message (bypasses batching).
 */
export declare function sendImmediateMessage(playerId: string, type: string, data: Record<string, unknown>): boolean;
/**
 * Flush all pending batches for a player.
 */
export declare function flushPlayerMessages(playerId: string): BatchedPayload | null;
/**
 * Log batch messaging statistics.
 */
export declare function logBatchStats(): void;
export declare const batchMessagingService: {
    MessageBatcher: typeof MessageBatcher;
    BatchMessageManager: typeof BatchMessageManager;
    getBatchMessageManager: typeof getBatchMessageManager;
    sendBatchedMessage: typeof sendBatchedMessage;
    sendImmediateMessage: typeof sendImmediateMessage;
    flushPlayerMessages: typeof flushPlayerMessages;
    deduplicateBatch: typeof deduplicateBatch;
    mergeBatch: typeof mergeBatch;
    logBatchStats: typeof logBatchStats;
};
//# sourceMappingURL=batchMessaging.d.ts.map