/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { IChannelAttributes, IChannelFactory, IChannelServices, IChannelStorageService, IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
import { ISharedObject } from "@fluidframework/shared-object-base";
import { ICodecOptions } from "../codec";
import { InMemoryStoredSchemaRepository } from "../core";
import { SharedTreeCore } from "../shared-tree-core";
import { DefaultEditBuilder, DefaultChangeset, SchemaEditor, FieldSchema } from "../feature-libraries";
import { JsonCompatibleReadOnly } from "../util";
import { InitializeAndSchematizeConfiguration } from "./schematizedTree";
import { ISharedTreeView } from "./sharedTreeView";
/**
 * Collaboratively editable tree distributed data-structure,
 * powered by {@link @fluidframework/shared-object-base#ISharedObject}.
 *
 * See [the README](../../README.md) for details.
 * @public
 */
export interface ISharedTree extends ISharedObject {
    /**
     * Get view without schematizing.
     *
     * @deprecated This API will be removed as part of making views use view schema.
     */
    readonly view: ISharedTreeView;
    /**
     * Takes in a tree and returns a view of it that conforms to the view schema.
     * The returned view referees to and can edit the provided one: it is not a fork of it.
     * Updates the stored schema in the tree to match the provided one if requested by config and compatible.
     *
     * If the tree is uninitialized (has no nodes or schema at all),
     * it is initialized to the config's initial tree and the provided schema are stored.
     * This is done even if `AllowedUpdateType.None`.
     *
     * @remarks
     * Doing initialization here, regardless of `AllowedUpdateType`, allows a small API that is hard to use incorrectly.
     * Other approach tend to have leave easy to make mistakes.
     * For example, having a separate initialization function means apps can forget to call it, making an app that can only open existing document,
     * or call it unconditionally leaving an app that can only create new documents.
     * It also would require the schema to be passed into to separate places and could cause issues if they didn't match.
     * Since the initialization function couldn't return a typed tree, the type checking wouldn't help catch that.
     * Also, if an app manages to create a document, but the initialization fails to get persisted, an app that only calls the initialization function
     * on the create code-path (for example how a schematized factory might do it),
     * would leave the document in an unusable state which could not be repaired when it is reopened (by the same or other clients).
     * Additionally, once out of schema content adapters are properly supported (with lazy document updates),
     * this initialization could become just another out of schema content adapter: at tha point it clearly belong here in schematize.
     *
     * TODO:
     * - Implement schema-aware API for return type.
     * - Support adapters for handling out of schema data.
     */
    schematize<TRoot extends FieldSchema>(config: InitializeAndSchematizeConfiguration<TRoot>): ISharedTreeView;
}
/**
 * Shared tree, configured with a good set of indexes and field kinds which will maintain compatibility over time.
 *
 * TODO: detail compatibility requirements.
 */
export declare class SharedTree extends SharedTreeCore<DefaultEditBuilder, DefaultChangeset> implements ISharedTree {
    private readonly _events;
    readonly view: ISharedTreeView;
    readonly storedSchema: SchemaEditor<InMemoryStoredSchemaRepository>;
    private readonly nodeKeyIndex;
    constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, optionsParam: SharedTreeOptions, telemetryContextPrefix: string);
    schematize<TRoot extends FieldSchema>(config: InitializeAndSchematizeConfiguration<TRoot>): ISharedTreeView;
    /**
     * TODO: Shared tree needs a pattern for handling non-changeset operations.
     * Whatever pattern is adopted should probably also handle multiple versions of changeset operations.
     * A single top level enum listing all ops (including their different versions),
     * with at least fine grained enough detail to direct them to the correct subsystem would be a good approach.
     * The current use-case (with an op applying to a specific index) is a temporary hack,
     * and its not clear how it would fit into such a system if implemented in shared-tree-core:
     * maybe op dispatch is part of the shared-tree level?
     */
    protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
    protected reSubmitCore(content: JsonCompatibleReadOnly, localOpMetadata: unknown): void;
    protected applyStashedOp(content: JsonCompatibleReadOnly): undefined;
    protected loadCore(services: IChannelStorageService): Promise<void>;
}
/**
 * @public
 */
export interface SharedTreeOptions extends Partial<ICodecOptions> {
    /**
     * The {@link ForestType} indicating which forest type should be created for the SharedTree.
     */
    forest?: ForestType;
}
/**
 * Used to distinguish between different forest types.
 * @public
 */
export declare enum ForestType {
    /**
     * The "ObjectForest" forest type.
     */
    Reference = 0,
    /**
     * The "ChunkedForest" forest type.
     */
    Optimized = 1
}
export declare const defaultSharedTreeOptions: Required<SharedTreeOptions>;
/**
 * A channel factory that creates {@link ISharedTree}s.
 * @public
 */
export declare class SharedTreeFactory implements IChannelFactory {
    private readonly options;
    type: string;
    attributes: IChannelAttributes;
    constructor(options?: SharedTreeOptions);
    load(runtime: IFluidDataStoreRuntime, id: string, services: IChannelServices, channelAttributes: Readonly<IChannelAttributes>): Promise<ISharedTree>;
    create(runtime: IFluidDataStoreRuntime, id: string): ISharedTree;
}
//# sourceMappingURL=sharedTree.d.ts.map