/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import type { ErasedType, IFluidLoadable } from "@fluidframework/core-interfaces/internal";
import type { IChannelStorageService } from "@fluidframework/datastore-definitions/internal";
import type { IIdCompressor } from "@fluidframework/id-compressor";
import type { IChannelView, IFluidSerializer, SharedKernel } from "@fluidframework/shared-object-base/internal";
import { type ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
import { type CodecWriteOptions, type ICodecOptions } from "../codec/index.js";
import { type FieldKey, type GraphCommit, type IEditableForest, type JsonableTree, type TreeNodeSchemaIdentifier, type TreeStoredSchema, TreeStoredSchemaRepository, type TreeStoredSchemaSubscription } from "../core/index.js";
import { TreeCompressionStrategy, type TreeCompressionStrategyPrivate } from "../feature-libraries/index.js";
import { type ClonableSchemaAndPolicy, SharedTreeCore } from "../shared-tree-core/index.js";
import { type ITree, type ImplicitFieldSchema, type ReadSchema, type SimpleTreeSchema, type TreeView, type TreeViewAlpha, type TreeViewConfiguration, type UnsafeUnknownSchema, type VerboseTree, type ITreeAlpha } from "../simple-tree/index.js";
import { SchematizingSimpleTreeView } from "./schematizingTreeView.js";
import type { SharedTreeChange } from "./sharedTreeChangeTypes.js";
import type { SharedTreeEditBuilder } from "./sharedTreeEditBuilder.js";
import { type TreeCheckout, type BranchableTree } from "./treeCheckout.js";
import { type Breakable, type JsonCompatible } from "../util/index.js";
/**
 * Copy of data from an {@link ITreePrivate} at some point in time.
 * @remarks
 * This is unrelated to Fluids concept of "snapshots".
 */
export interface SharedTreeContentSnapshot {
    /**
     * The schema stored in the document.
     *
     * @remarks
     * Edits to the schema can mutate the schema stored of the tree which took this snapshot (but this snapshot will remain the same)
     * This is mainly useful for debugging cases where schematize reports an incompatible view schema.
     */
    readonly schema: TreeStoredSchema;
    /**
     * All {@link TreeStatus.InDocument} content.
     */
    readonly tree: JsonableTree[];
    /**
     * All {@link TreeStatus.Removed} content.
     */
    readonly removed: [string | number | undefined, number, JsonableTree][];
}
/**
 * {@link ITree} extended with some non-public APIs.
 * @internal
 */
export interface ITreeInternal extends IChannelView, ITreeAlpha {
}
/**
 * {@link ITreeInternal} extended with some non-exported APIs.
 * @remarks
 * This allows access to the tree content using the internal data model used at the storage and "flex" layers,
 * and should only be needed for testing and debugging this package's internals.
 */
export interface ITreePrivate extends ITreeInternal {
    /**
     * Provides a copy of the current content of the tree.
     * This can be useful for inspecting the tree when no suitable view schema is available.
     * This is only intended for use in testing and exceptional code paths: it is not performant.
     *
     * This does not include everything that is included in a tree summary, since information about how to merge future edits is omitted.
     */
    contentSnapshot(): SharedTreeContentSnapshot;
    /**
     * Access to internals for testing.
     */
    readonly kernel: SharedTreeKernel;
}
/**
 * The type SharedTree's kernel's view must implement so what when its merged with the underling SharedObject's API it fully implements the required tree API surface ({@link ITreePrivate }).
 */
export type SharedTreeKernelView = Omit<ITreePrivate, keyof (IChannelView & IFluidLoadable)>;
/**
 * SharedTreeCore, configured with a good set of indexes and field kinds which will maintain compatibility over time.
 *
 * TODO: detail compatibility requirements.
 */
export declare class SharedTreeKernel extends SharedTreeCore<SharedTreeEditBuilder, SharedTreeChange> implements SharedKernel {
    readonly checkout: TreeCheckout;
    get storedSchema(): TreeStoredSchemaRepository;
    /**
     * The app-facing API for SharedTree implemented by this Kernel.
     * @remarks
     * This is the API grafted onto the ISharedObject which apps can access.
     * It includes both the APIs used for internal testing, and public facing APIs (both stable and unstable).
     * Different users will have access to different subsets of this API, see {@link ITree}, {@link ITreeAlpha} and {@link ITreeInternal} which this {@link ITreePrivate} extends.
     */
    readonly view: SharedTreeKernelView;
    constructor(breaker: Breakable, sharedObject: IChannelView & IFluidLoadable, serializer: IFluidSerializer, submitLocalMessage: (content: unknown, localOpMetadata?: unknown) => void, lastSequenceNumber: () => number | undefined, logger: ITelemetryLoggerExt | undefined, idCompressor: IIdCompressor, optionsParam: SharedTreeOptionsInternal);
    exportVerbose(): VerboseTree | undefined;
    exportSimpleSchema(): SimpleTreeSchema;
    contentSnapshot(): SharedTreeContentSnapshot;
    viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(config: TreeViewConfiguration<ReadSchema<TRoot>>): SchematizingSimpleTreeView<TRoot> & TreeView<ReadSchema<TRoot>>;
    viewWith<TRoot extends ImplicitFieldSchema>(config: TreeViewConfiguration<TRoot>): SchematizingSimpleTreeView<TRoot> & TreeView<TRoot>;
    loadCore(services: IChannelStorageService): Promise<void>;
    didAttach(): void;
    applyStashedOp(...args: Parameters<SharedTreeCore<SharedTreeEditBuilder, SharedTreeChange>["applyStashedOp"]>): void;
    protected submitCommit(commit: GraphCommit<SharedTreeChange>, schemaAndPolicy: ClonableSchemaAndPolicy, isResubmit: boolean): void;
    onDisconnect(): void;
}
export declare function exportSimpleSchema(storedSchema: TreeStoredSchema): SimpleTreeSchema;
/**
 * A way to parse schema in the persisted format from {@link extractPersistedSchema}.
 * @remarks
 * This behaves identically to {@link ITreeAlpha.exportSimpleSchema},
 * except that it gets the schema from the caller instead of from an existing tree.
 *
 * This can be useful for inspecting the contents of persisted schema,
 * such as those generated by {@link extractPersistedSchema} for use in testing.
 * Since that data format is otherwise unspecified,
 * this provides a way to inspect its contents with documented semantics.
 * @alpha
 */
export declare function persistedToSimpleSchema(persisted: JsonCompatible, options: ICodecOptions): SimpleTreeSchema;
/**
 * Get a {@link BranchableTree} from a {@link ITree}.
 * @remarks The branch can be used for "version control"-style coordination of edits on the tree.
 * @privateRemarks This function will be removed if/when the branching API becomes public,
 * but it (or something like it) is necessary in the meantime to prevent the alpha types from being exposed as public.
 * @alpha
 * @deprecated This API is superseded by {@link TreeBranch}, which should be used instead.
 */
export declare function getBranch(tree: ITree): BranchableTree;
/**
 * Get a {@link BranchableTree} from a {@link TreeView}.
 * @remarks The branch can be used for "version control"-style coordination of edits on the tree.
 * Branches are currently an unstable "alpha" API and are subject to change in the future.
 * @privateRemarks This function will be removed if/when the branching API becomes public,
 * but it (or something like it) is necessary in the meantime to prevent the alpha types from being exposed as public.
 * @alpha
 * @deprecated This API is superseded by {@link TreeBranch}, which should be used instead.
 */
export declare function getBranch<T extends ImplicitFieldSchema | UnsafeUnknownSchema>(view: TreeViewAlpha<T>): BranchableTree;
/**
 * Format versions supported by SharedTree.
 *
 * Each version documents a required minimum version of the \@fluidframework/tree package.
 * @alpha
 */
export declare const SharedTreeFormatVersion: {
    /**
     * Requires \@fluidframework/tree \>= 2.0.0.
     *
     * @deprecated - FF does not currently plan on supporting this format long-term.
     * Do not write production documents using this format, as they may not be loadable in the future.
     */
    readonly v1: 1;
    /**
     * Requires \@fluidframework/tree \>= 2.0.0.
     */
    readonly v2: 2;
    /**
     * Requires \@fluidframework/tree \>= 2.0.0.
     */
    readonly v3: 3;
    /**
     * Requires \@fluidframework/tree \>= 2.0.0.
     */
    readonly v5: 5;
};
/**
 * Format versions supported by SharedTree.
 *
 * Each version documents a required minimum version of the \@fluidframework/tree package.
 * @alpha
 * @privateRemarks
 * See packages/dds/tree/docs/main/compatibility.md for information on how to add support for a new format.
 *
 * TODO: Before this gets promoted past Alpha,
 * a separate abstraction more suited for use in the public API should be adopted rather than reusing the same types used internally.
 * Such an abstraction should probably be in the form of a Fluid-Framework wide compatibility enum.
 */
export type SharedTreeFormatVersion = typeof SharedTreeFormatVersion;
/**
 * Configuration options for SharedTree.
 * @alpha @input
 */
export type SharedTreeOptions = Partial<CodecWriteOptions> & Partial<SharedTreeFormatOptions> & ForestOptions;
export interface SharedTreeOptionsInternal extends Omit<SharedTreeOptions, "treeEncodeType">, Partial<SharedTreeFormatOptionsInternal> {
    disposeForksAfterTransaction?: boolean;
    /**
     * 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.
     * @remarks
     * The policy for which fields should get incremental encoding should eventually be specified some other way.
     */
    shouldEncodeFieldIncrementally?(nodeIdentifier: TreeNodeSchemaIdentifier, fieldKey: FieldKey): boolean;
}
/**
 * Configuration options for SharedTree's internal tree storage.
 * @beta @input
 */
export interface ForestOptions {
    /**
     * The {@link ForestType} indicating which forest type should be created for the SharedTree.
     */
    readonly forest?: ForestType;
}
/**
 * Options for configuring the persisted format SharedTree uses.
 * @alpha @input
 */
export interface SharedTreeFormatOptions {
    /**
     * See {@link TreeCompressionStrategy}.
     * default: TreeCompressionStrategy.Compressed
     */
    treeEncodeType: TreeCompressionStrategy;
    /**
     * The format version SharedTree should use to persist documents.
     *
     * This option has compatibility implications for applications using SharedTree.
     * Each version documents a required minimum version of \@fluidframework/tree.
     * If this minimum version fails to be met, the SharedTree may fail to load.
     * To be safe, application authors should verify that they have saturated this version
     * of \@fluidframework/tree in their ecosystem before changing the format version.
     *
     * This option defaults to SharedTreeFormatVersion.v2.
     */
    formatVersion: SharedTreeFormatVersion[keyof SharedTreeFormatVersion];
}
export interface SharedTreeFormatOptionsInternal extends Omit<SharedTreeFormatOptions, "treeEncodeType"> {
    treeEncodeType: TreeCompressionStrategyPrivate;
}
/**
 * Used to distinguish between different forest types.
 * @remarks
 * The "Forest" is the internal data structure used to store all the trees (the main tree and any removed ones) for a given view or branch.
 * ForestTypes should all have the same behavior, but may differ in performance and debuggability.
 *
 * Current options are {@link ForestTypeReference}, {@link ForestTypeOptimized} and {@link ForestTypeExpensiveDebug}.
 * @privateRemarks
 * Implement using {@link toForestType}.
 * Consume using {@link buildConfiguredForest}.
 * @sealed @beta
 */
export interface ForestType extends ErasedType<"ForestType"> {
}
/**
 * Reference implementation of forest.
 * @remarks
 * A simple implementation with minimal complexity and moderate debuggability, validation and performance.
 * @privateRemarks
 * The "ObjectForest" forest type.
 * @alpha
 */
export declare const ForestTypeReference: ForestType;
/**
 * Optimized implementation of forest.
 * @remarks
 * A complex optimized forest implementation, which has minimal validation and debuggability to optimize for performance.
 * Uses an internal representation optimized for size designed to scale to larger datasets with reduced overhead.
 * @privateRemarks
 * The "ChunkedForest" forest type.
 * @alpha
 */
export declare const ForestTypeOptimized: ForestType;
/**
 * Slow implementation of forest intended only for debugging.
 * @remarks
 * Includes validation with scales poorly.
 * May be asymptotically slower than {@link ForestTypeReference}, and may perform very badly with larger data sizes.
 * @privateRemarks
 * The "ObjectForest" forest type with expensive asserts for debugging.
 * @alpha
 */
export declare const ForestTypeExpensiveDebug: ForestType;
/**
 * Build and return a forest of the requested type.
 */
export declare function buildConfiguredForest(breaker: Breakable, factory: ForestType, schema: TreeStoredSchemaSubscription, idCompressor: IIdCompressor): IEditableForest;
export declare const defaultSharedTreeOptions: Required<SharedTreeOptionsInternal>;
//# sourceMappingURL=sharedTree.d.ts.map