/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import type { IFluidLoadable, ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
import type { IChannelStorageService } from "@fluidframework/datastore-definitions/internal";
import type { IIdCompressor } from "@fluidframework/id-compressor";
import type { IExperimentalIncrementalSummaryContext, IRuntimeMessageCollection, ISummaryTreeWithStats, ITelemetryContext } from "@fluidframework/runtime-definitions/internal";
import type { IChannelView, IFluidSerializer } from "@fluidframework/shared-object-base/internal";
import type { ICodecOptions } from "../codec/index.js";
import { type ChangeFamily, type ChangeFamilyEditor, type GraphCommit, type RevisionTag, type SchemaAndPolicy, type SchemaPolicy, type TreeStoredSchemaRepository } from "../core/index.js";
import { type JsonCompatibleReadOnly, type Breakable, type WithBreakable } from "../util/index.js";
import type { SharedTreeBranch } from "./branch.js";
import { BranchCommitEnricher } from "./branchCommitEnricher.js";
import { type ChangeEnricherReadonlyCheckout } from "./changeEnricher.js";
import type { ResubmitMachine } from "./resubmitMachine.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 other configuration.
 */
export declare class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange> implements WithBreakable {
    readonly breaker: Breakable;
    readonly sharedObject: IChannelView & IFluidLoadable;
    readonly serializer: IFluidSerializer;
    readonly submitLocalMessage: (content: unknown, localOpMetadata?: unknown) => void;
    private readonly idCompressor;
    readonly getEditor: () => TEditor;
    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 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 resubmitMachine;
    readonly commitEnricher: BranchCommitEnricher<TChange>;
    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 runtime - The IFluidDataStoreRuntime which contains the shared object
     * @param editor - 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.
     */
    constructor(breaker: Breakable, sharedObject: IChannelView & IFluidLoadable, serializer: IFluidSerializer, submitLocalMessage: (content: unknown, localOpMetadata?: unknown) => void, logger: ITelemetryBaseLogger | undefined, summarizables: readonly Summarizable[], changeFamily: ChangeFamily<TEditor, TChange>, options: ICodecOptions, formatOptions: ExplicitCoreCodecVersions, idCompressor: IIdCompressor, schema: TreeStoredSchemaRepository, schemaPolicy: SchemaPolicy, resubmitMachine?: ResubmitMachine<TChange>, enricher?: ChangeEnricherReadonlyCheckout<TChange>, getEditor?: () => TEditor);
    summarizeCore(serializer: IFluidSerializer, telemetryContext?: ITelemetryContext, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext, fullTree?: boolean): ISummaryTreeWithStats;
    loadCore(services: IChannelStorageService): Promise<void>;
    private loadSummarizable;
    /**
     * 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.
     */
    protected submitCommit(commit: GraphCommit<TChange>, schemaAndPolicy: ClonableSchemaAndPolicy, isResubmit: boolean): void;
    /**
     * Process a bunch of messages from the runtime. SharedObject will call this method with a bunch of messages.
     */
    processMessagesCore(messagesCollection: IRuntimeMessageCollection): void;
    getLocalBranch(): SharedTreeBranch<TEditor, TChange>;
    didAttach(): void;
    reSubmitCore(content: JsonCompatibleReadOnly, localOpMetadata: unknown): void;
    applyStashedOp(content: JsonCompatibleReadOnly): void;
}
/**
 * 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).summarize}
     * @param stringify - Serializes the contents of the component (including {@link (IFluidHandle:interface)}s) for storage.
     * @param fullTree - A flag indicating whether the attempt should generate a full
     * summary tree without any handles for unchanged subtrees. It should only be set to true when generating
     * a summary from the entire container. The default value is false.
     * @param trackState - An optimization for tracking state of objects across summaries. If the state
     * of an object did not change since last successful summary, an
     * {@link @fluidframework/protocol-definitions#ISummaryHandle} can be used
     * instead of re-summarizing it. If this is `false`, the expectation is that you should never
     * send an `ISummaryHandle`, since you are not expected to track state. The default value is true.
     * @param telemetryContext - See {@link @fluidframework/runtime-definitions#ITelemetryContext}.
     * @param incrementalSummaryContext - See {@link @fluidframework/runtime-definitions#IExperimentalIncrementalSummaryContext}.
     */
    summarize(props: {
        stringify: SummaryElementStringifier;
        fullTree?: boolean;
        trackState?: boolean;
        telemetryContext?: ITelemetryContext;
        incrementalSummaryContext?: IExperimentalIncrementalSummaryContext;
    }): ISummaryTreeWithStats;
    /**
     * 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