/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { IChannelAttributes, IChannelStorageService, IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
import { ITelemetryContext, ISummaryTreeWithStats, IGarbageCollectionData } from "@fluidframework/runtime-definitions";
import { IFluidSerializer, ISharedObjectEvents, SharedObject } from "@fluidframework/shared-object-base";
import { ICodecOptions } from "../codec";
import { ChangeFamily, Delta, ChangeFamilyEditor, IRepairDataStoreProvider } from "../core";
import { JsonCompatibleReadOnly } from "../util";
import { TransformEvents } from "../events";
import { SharedTreeBranch } from "./branch";
/**
 * The events emitted by a {@link SharedTreeCore}
 *
 * TODO: Add/remove events
 */
export interface ISharedTreeCoreEvents {
    updated: () => void;
}
/**
 * Events which result from the state of the tree changing.
 * These are for internal use by the tree.
 */
export interface ChangeEvents<TChangeset> {
    /**
     * @param change - change that was just sequenced.
     * @param derivedFromLocal - iff provided, change was a local change (from this session)
     * which is now sequenced (and thus no longer local).
     */
    newSequencedChange: (change: TChangeset, derivedFromLocal?: TChangeset) => void;
    /**
     * @param change - change that was just applied locally.
     */
    newLocalChange: (change: TChangeset) => void;
    /**
     * @param changeDelta - composed changeset from previous local state
     * (state after all sequenced then local changes are accounted for) to current local state.
     * May involve effects of a new sequenced change (including rebasing of local changes onto it),
     * or a new local change. Called after either sequencedChange or newLocalChange.
     */
    newLocalState: (changeDelta: Delta.Root) => void;
}
/**
 * Generic shared tree, which needs to be configured with indexes, field kinds and a history policy to be used.
 *
 * TODO: actually implement
 * TODO: is history policy a detail of what indexes are used, or is there something else to it?
 */
export declare class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange> extends SharedObject<TransformEvents<ISharedTreeCoreEvents, ISharedObjectEvents>> {
    private readonly changeFamily;
    private readonly editManager;
    private readonly summarizables;
    /** Iff false, calls to `submitOp` will have no effect */
    private submitOps;
    /**
     * The sequence number that this instance is at.
     * This is number is artificial in that it is made up by this instance as opposed to being provided by the runtime.
     * Is `undefined` after (and only after) this instance is attached.
     */
    private detachedRevision;
    /**
     * Provides internal events that result from changes to the tree
     */
    protected readonly changeEvents: import("../events").ISubscribable<ChangeEvents<TChange>> & import("../events").IEmitter<ChangeEvents<TChange>> & import("../events").HasListeners<ChangeEvents<TChange>>;
    /**
     * Used to edit the state of the tree. Edits will be immediately applied locally to the tree.
     * If there is no transaction currently ongoing, then the edits will be submitted to Fluid immediately as well.
     */
    get editor(): TEditor;
    /**
     * Used to encode/decode messages sent to/received from the Fluid runtime.
     *
     * @remarks Since there is currently only one format, this can just be cached on the class.
     * With more write formats active, it may make sense to keep around the "usual" format codec
     * (the one for the current persisted configuration) and resolve codecs for different versions
     * as necessary (e.g. an upgrade op came in, or the configuration changed within the collab window
     * and an op needs to be interpreted which isn't written with the current configuration).
     */
    private readonly messageCodec;
    /**
     * @param summarizables - Summarizers for all indexes used by this tree
     * @param changeFamily - The change family
     * @param editManager - The edit manager
     * @param id - The id of the shared object
     * @param runtime - The IFluidDataStoreRuntime which contains the shared object
     * @param attributes - Attributes of the shared object
     * @param telemetryContextPrefix - the context for any telemetry logs/errors emitted
     */
    constructor(summarizables: readonly Summarizable[], changeFamily: ChangeFamily<TEditor, TChange>, repairDataStoreProvider: IRepairDataStoreProvider<TChange>, options: ICodecOptions, id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, telemetryContextPrefix: string);
    protected summarizeCore(serializer: IFluidSerializer, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
    protected loadCore(services: IChannelStorageService): Promise<void>;
    /**
     * Submits an op to the Fluid runtime containing the given commit
     * @param commit - the commit to submit
     */
    private submitCommit;
    protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
    /**
     * Undoes the last completed transaction made by the client.
     * It is invalid to call it while a transaction is open (this will be supported in the future).
     */
    undo(): void;
    /**
     * Redoes the last completed undo made by the client.
     * It is invalid to call it while a transaction is open (this will be supported in the future).
     */
    redo(): void;
    /**
     * @returns the head commit of the root local branch
     */
    protected getLocalBranch(): SharedTreeBranch<TEditor, TChange>;
    protected onDisconnect(): void;
    protected didAttach(): void;
    protected reSubmitCore(content: JsonCompatibleReadOnly, localOpMetadata: unknown): void;
    protected applyStashedOp(content: JsonCompatibleReadOnly): undefined;
    getGCData(fullGC?: boolean): IGarbageCollectionData;
}
/**
 * Specifies the behavior of a component that puts data in a summary.
 */
export interface Summarizable {
    /**
     * Field name in summary json under which this element stores its data.
     */
    readonly key: string;
    /**
     * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}
     * @param stringify - Serializes the contents of the component (including {@link IFluidHandle}s) for storage.
     */
    getAttachSummary(stringify: SummaryElementStringifier, fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
    /**
     * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
     * @param stringify - Serializes the contents of the component (including {@link IFluidHandle}s) for storage.
     */
    summarize(stringify: SummaryElementStringifier, fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): Promise<ISummaryTreeWithStats>;
    /**
     * {@inheritDoc (ISharedObject:interface).getGCData}
     */
    getGCData(fullGC?: boolean): IGarbageCollectionData;
    /**
     * Allows the component to perform custom loading. The storage service is scoped to this component and therefore
     * paths in this component will not collide with those in other components, even if they are the same string.
     * @param service - Storage used by the component
     * @param parse - Parses serialized data from storage into runtime objects for the component
     */
    load(service: IChannelStorageService, parse: SummaryElementParser): Promise<void>;
}
/**
 * Serializes the given contents into a string acceptable for storing in summaries, i.e. all
 * Fluid handles have been replaced appropriately by an IFluidSerializer
 */
export declare type SummaryElementStringifier = (contents: unknown) => string;
/**
 * Parses a serialized/summarized string into an object, rehydrating any Fluid handles as necessary
 */
export declare type SummaryElementParser = (contents: string) => unknown;
//# sourceMappingURL=sharedTreeCore.d.ts.map