/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import type { IChannelAttributes, IFluidDataStoreRuntime, IChannelStorageService } from "@fluidframework/datastore-definitions/internal";
import type { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
import type { IExperimentalIncrementalSummaryContext, IGarbageCollectionData, ISummaryTreeWithStats, ITelemetryContext } from "@fluidframework/runtime-definitions/internal";
import { type IFluidSerializer, SharedObject } from "@fluidframework/shared-object-base/internal";
import type { ICodecOptions } from "../codec/index.js";
import { type ChangeFamily, type ChangeFamilyEditor, type RevisionTag, type SchemaAndPolicy, type SchemaPolicy, type TreeStoredSchemaRepository } from "../core/index.js";
import { type JsonCompatibleReadOnly } from "../util/index.js";
import { type SharedTreeBranch } from "./branch.js";
import { type ChangeEnricherReadonlyCheckout } from "./changeEnricher.js";
import type { ResubmitMachine } from "./resubmitMachine.js";
import { BranchCommitEnricher } from "./branchCommitEnricher.js";
export interface ExplicitCoreCodecVersions {
    editManager: number;
    message: number;
}
export interface ClonableSchemaAndPolicy extends SchemaAndPolicy {
    schema: TreeStoredSchemaRepository;
}
/**
 * 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 {
    private readonly editManager;
    private readonly summarizables;
    /**
     * The sequence number that this instance is at.
     * This 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;
    /**
     * 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;
    private readonly idCompressor;
    private readonly resubmitMachine;
    protected readonly commitEnricher: BranchCommitEnricher<TChange>;
    protected readonly mintRevisionTag: () => RevisionTag;
    private readonly schemaAndPolicy;
    /**
     * @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 property prefix for telemetry pertaining to this object. See {@link ITelemetryContext}
     */
    constructor(summarizables: readonly Summarizable[], changeFamily: ChangeFamily<TEditor, TChange>, options: ICodecOptions, formatOptions: ExplicitCoreCodecVersions, id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, telemetryContextPrefix: string, schema: TreeStoredSchemaRepository, schemaPolicy: SchemaPolicy, resubmitMachine?: ResubmitMachine<TChange>, enricher?: ChangeEnricherReadonlyCheckout<TChange>);
    protected summarizeCore(serializer: IFluidSerializer, telemetryContext?: ITelemetryContext, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext): ISummaryTreeWithStats;
    protected loadCore(services: IChannelStorageService): Promise<void>;
    /**
     * Submits an op to the Fluid runtime containing the given commit
     * @param commit - the commit to submit
     * @returns the submitted commit. This is undefined if the underlying `SharedObject` is not attached,
     * and may differ from `commit` due to enrichments like detached tree refreshers.
     */
    private submitCommit;
    protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): 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): void;
    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:interface)}s) for storage.
     */
    getAttachSummary(stringify: SummaryElementStringifier, fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext): ISummaryTreeWithStats;
    /**
     * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
     * @param stringify - Serializes the contents of the component (including {@link (IFluidHandle:interface)}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 type SummaryElementStringifier = (contents: unknown) => string;
/**
 * Parses a serialized/summarized string into an object, rehydrating any Fluid handles as necessary
 */
export type SummaryElementParser = (contents: string) => unknown;
//# sourceMappingURL=sharedTreeCore.d.ts.map