/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
import { type InboundSequencedContainerRuntimeMessage } from "../messageTypes.js";
import { OpDecompressor } from "./opDecompressor.js";
import { OpGroupingManager } from "./opGroupingManager.js";
import { OpSplitter } from "./opSplitter.js";
/**
 * Info about the batch we learn when we process the first message
 */
export interface BatchStartInfo {
    /**
     * Batch ID, if present
     */
    readonly batchId: string | undefined;
    /**
     * clientId that sent this batch. Used to compute Batch ID if needed
     */
    readonly clientId: string;
    /**
     * Client Sequence Number of the Grouped Batch message, or the first message in the ungrouped batch.
     * Used to compute Batch ID if needed
     *
     * @remarks For chunked batches, this is the CSN of the "representative" chunk (the final chunk).
     * For grouped batches, clientSequenceNumber on messages is overwritten, so we track this original value here.
     */
    readonly batchStartCsn: number;
    /**
     * The first message in the batch, or if the batch is empty, the empty grouped batch message.
     * Used for accessing the sequence numbers for the (start of the) batch.
     *
     * @remarks Do not use clientSequenceNumber here, use batchStartCsn instead.
     */
    readonly keyMessage: ISequencedDocumentMessage;
}
/**
 * Result of processing the next inbound message.
 * Depending on the message and configuration of RemoteMessageProcessor, the result may be:
 * - A full batch of messages (including a single-message batch)
 * - The first message of a multi-message batch
 * - The next message in a multi-message batch
 */
export type InboundMessageResult = {
    type: "fullBatch";
    messages: InboundSequencedContainerRuntimeMessage[];
    batchStart: BatchStartInfo;
    length: number;
    groupedBatch: boolean;
} | {
    type: "batchStartingMessage";
    batchStart: BatchStartInfo;
    nextMessage: InboundSequencedContainerRuntimeMessage;
    length?: never;
} | {
    type: "nextBatchMessage";
    batchEnd?: boolean;
    nextMessage: InboundSequencedContainerRuntimeMessage;
    length?: never;
};
/**
 * Stateful class for processing incoming remote messages as the virtualization measures are unwrapped,
 * potentially across numerous inbound ops.
 *
 * @internal
 */
export declare class RemoteMessageProcessor {
    private readonly opSplitter;
    private readonly opDecompressor;
    private readonly opGroupingManager;
    private batchInProgress;
    constructor(opSplitter: OpSplitter, opDecompressor: OpDecompressor, opGroupingManager: OpGroupingManager);
    get partialMessages(): ReadonlyMap<string, string[]>;
    clearPartialMessagesFor(clientId: string): void;
    /**
     * Ungroups and Unchunks the runtime ops of a batch received over the wire
     * @param remoteMessageCopy - A shallow copy of a message from another client, possibly virtualized
     * (grouped, compressed, and/or chunked).
     * Being a shallow copy, it's considered mutable, meaning no other Container or other parallel procedure
     * depends on this object instance.
     * Note remoteMessageCopy.contents (and other object props) MUST not be modified,
     * but may be overwritten (as is the case with contents).
     *
     * Incoming messages will always have compression, chunking, and grouped batching happen in a defined order and that order cannot be changed.
     * When processing these messages, the order is:
     * 1. If chunked, process the chunk and only continue if this is a final chunk
     * 2. If compressed, decompress the message and store for further unrolling of the decompressed content
     * 3. If grouped, ungroup the message
     * For more details, see https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/src/opLifecycle/README.md#inbound
     *
     * @returns all the unchunked, decompressed, ungrouped, unpacked InboundSequencedContainerRuntimeMessage from a single batch
     * or undefined if the batch is not yet complete.
     */
    process(remoteMessageCopy: ISequencedDocumentMessage, logLegacyCase: (codePath: string) => void): InboundMessageResult | undefined;
    /**
     * Now that the message has been "unwrapped" as to any virtualization (grouping, compression, chunking),
     * inspect the batch metadata flag and determine what kind of result to return.
     */
    private getResultBasedOnBatchMetadata;
}
/**
 * Unpacks runtime messages.
 *
 * @remarks This API makes no promises regarding backward-compatibility. This is internal API.
 * @param message - message (as it observed in storage / service)
 * @returns whether the given message was unpacked
 *
 * @internal
 */
export declare function unpackRuntimeMessage(message: ISequencedDocumentMessage, logLegacyCase?: (codePath: string) => void): boolean;
//# sourceMappingURL=remoteMessageProcessor.d.ts.map