/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import type { IIdCompressor, SessionId } from "@fluidframework/id-compressor";
import { VersionDispatchingCodecBuilder, type VersionDispatchingCodec } from "../../../codec/index.js";
import { type ITreeCursorSynchronous, type SchemaAndPolicy, type TreeChunk } from "../../../core/index.js";
import { type Brand } from "../../../util/index.js";
import { TreeCompressionStrategy } from "../../treeCompressionUtils.js";
import type { FieldBatch } from "./fieldBatch.js";
import { EncodedFieldBatchV2, FieldBatchFormatVersion } from "./format/index.js";
import type { IncrementalEncodingPolicy } from "./incrementalEncodingPolicy.js";
/**
 * Reference ID for a chunk that is incrementally encoded.
 */
export type ChunkReferenceId = Brand<number, "forest.ChunkReferenceId">;
/**
 * Properties for incremental encoding.
 * Fields that support incremental encoding will encode their chunks separately by calling `encodeIncrementalField`.
 * @remarks
 * This supports features like incremental summarization where the summary from these fields can be re-used if
 * unchanged between summaries.
 * Note that each of these chunks that are incrementally encoded is fully self-describing (contain its own shapes
 * list and identifier table) and does not rely on context from its parent.
 */
export interface IncrementalEncoder {
    /**
     * Returns whether a node / field should be incrementally encoded.
     * @remarks See {@link IncrementalEncodingPolicy}.
     */
    shouldEncodeIncrementally: IncrementalEncodingPolicy;
    /**
     * Called to encode an incremental field at the cursor.
     * The chunks for this field are encoded separately from the main buffer.
     * @param cursor - The cursor pointing to the field to encode.
     * @param chunkEncoder - A function that encodes the contents of the passed chunk in the field.
     * @returns The reference IDs of the encoded chunks in the field.
     * This is used to retrieve the encoded chunks later.
     */
    encodeIncrementalField(cursor: ITreeCursorSynchronous, chunkEncoder: (chunk: TreeChunk) => EncodedFieldBatchV2): ChunkReferenceId[];
}
/**
 * Properties for incremental decoding.
 *
 * Fields that had their chunks incrementally encoded will retrieve them by calling `getEncodedIncrementalChunk`.
 * @remarks
 * See {@link IncrementalEncoder} for more details.
 */
export interface IncrementalDecoder {
    /**
     * Called to decode an incremental chunk with the given reference ID.
     * @param referenceId - The reference ID of the chunk to decode.
     * @param chunkDecoder - A function that decodes the chunk.
     * @returns The decoded chunk.
     */
    decodeIncrementalChunk(referenceId: ChunkReferenceId, chunkDecoder: (encoded: EncodedFieldBatchV2) => TreeChunk): TreeChunk;
}
/**
 * Combines the properties of {@link IncrementalEncoder} and {@link IncrementalDecoder}.
 */
export interface IncrementalEncoderDecoder extends IncrementalEncoder, IncrementalDecoder {
}
export interface FieldBatchEncodingContext {
    readonly encodeType: TreeCompressionStrategy;
    readonly idCompressor: IIdCompressor;
    readonly originatorId: SessionId;
    readonly schema?: SchemaAndPolicy;
    /**
     * An encoder / decoder for encoding and decoding of incremental fields.
     * This will be defined if incremental encoding is supported and enabled.
     */
    readonly incrementalEncoderDecoder?: IncrementalEncoderDecoder;
    /**
     * `true` when encoding to or decoding from a summary blob. `false` for
     * op-stream encode/decode paths and for utility encoders that are not
     * tied to a persisted document. Healing behavior is gated on this flag.
     */
    readonly isSummary: boolean;
    /**
     * If `true`, when an op-space compressed ID encountered while decoding
     * cannot be resolved by the local id-compressor (e.g. the attach-summary
     * blob's originator session state was stripped), a deterministic stable
     * UUID derived from `sharedObjectId` is returned instead of throwing.
     * @remarks
     * Off by default. Used only to recover documents whose attach summary was
     * written with non-finalized op-space IDs before the encode-side fix
     * shipped. Only takes effect when `isSummary` is also `true`.
     * See {@link SharedTreeOptionsBeta.healUnresolvableIdentifiersOnDecode}.
     */
    readonly healUnresolvableIdentifiersOnDecode?: boolean;
    /**
     * The SharedTree's shared-object id, used as input to the deterministic
     * UUID derivation when `healUnresolvableIdentifiersOnDecode` triggers. Required
     * for that path; ignored otherwise.
     * @remarks
     * This allows us to ensure that multiple attaches,
     * in the same or different documents, with the same session offsets, get different UUIDs.
     */
    readonly sharedObjectId?: string;
}
/**
 * @remarks
 * Fields in this batch currently don't have field schema for the root, which limits optimizations.
 */
export type FieldBatchCodec = VersionDispatchingCodec<FieldBatch, FieldBatchEncodingContext, FieldBatchFormatVersion>;
/**
 * {@link VersionDispatchingCodecBuilder} for field batch codecs.
 */
export declare const fieldBatchCodecBuilder: VersionDispatchingCodecBuilder<import("../../../codec/codec.js").ICodecOptions, FieldBatch, FieldBatchEncodingContext, Brand<1, "FieldBatchFormatVersion"> | Brand<2, "FieldBatchFormatVersion">, "FieldBatch", FieldBatchEncodingContext>;
//# sourceMappingURL=codecs.d.ts.map