/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import type { IIdCompressor, SessionId } from "@fluidframework/id-compressor";
import { type FluidClientVersion, type ICodecOptions, type IJsonCodec } from "../../../codec/index.js";
import { type FieldKey, type ITreeCursorSynchronous, type SchemaAndPolicy, type TreeChunk, type TreeNodeSchemaIdentifier } from "../../../core/index.js";
import { type Brand, type JsonCompatibleReadOnly } from "../../../util/index.js";
import { type TreeCompressionStrategyPrivate } from "../../treeCompressionUtils.js";
import type { FieldBatch } from "./fieldBatch.js";
import { EncodedFieldBatch } from "./format.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 field should be incrementally encoded.
     * @param nodeIdentifier - The identifier of the node containing the field.
     * @param fieldKey - The key of the field to check.
     */
    shouldEncodeFieldIncrementally(nodeIdentifier: TreeNodeSchemaIdentifier, fieldKey: FieldKey): boolean;
    /**
     * 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) => EncodedFieldBatch): 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 get the encoded contents of an chunk in an incremental field with the given reference ID.
     * @param referenceId - The reference ID of the chunk to retrieve.
     * @returns The encoded contents of the chunk.
     */
    getEncodedIncrementalChunk: (referenceId: ChunkReferenceId) => EncodedFieldBatch;
}
/**
 * Combines the properties of {@link IncrementalEncoder} and {@link IncrementalDecoder}.
 */
export interface IncrementalEncoderDecoder extends IncrementalEncoder, IncrementalDecoder {
}
export interface FieldBatchEncodingContext {
    readonly encodeType: TreeCompressionStrategyPrivate;
    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;
}
/**
 * @remarks
 * Fields in this batch currently don't have field schema for the root, which limits optimizations.
 */
export type FieldBatchCodec = IJsonCodec<FieldBatch, EncodedFieldBatch, JsonCompatibleReadOnly, FieldBatchEncodingContext>;
/**
 * Get the write version for {@link makeFieldBatchCodec} based on the `oldestCompatibleClient` version.
 * @privateRemarks
 * TODO: makeFieldBatchCodec (and makeVersionDispatchingCodec transitively) should bake in this versionToFormat logic and the resulting codec can then support use with FluidClientVersion directly.
 */
export declare function fluidVersionToFieldBatchCodecWriteVersion(oldestCompatibleClient: FluidClientVersion): number;
export declare function makeFieldBatchCodec(options: ICodecOptions, writeVersion: number): FieldBatchCodec;
//# sourceMappingURL=codecs.d.ts.map