/*!
 * 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 { SummaryTreeBuilder } from "@fluidframework/runtime-utils/internal";
import type { IChannelView, IFluidSerializer } from "@fluidframework/shared-object-base/internal";
import type { CodecWriteOptions, DependentFormatVersion } 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 { BranchId, SharedTreeBranch } from "./branch.js";
import { BranchCommitEnricher } from "./branchCommitEnricher.js";
import type { ChangeEnricher } from "./changeEnricher.js";
import type { EditManagerFormatVersion } from "./editManagerFormatCommons.js";
import type { MessageFormatVersion } from "./messageFormat.js";
import type { ResubmitMachine } from "./resubmitMachine.js";
import { type SharedTreeSummaryFormatVersion, type Summarizable, type SummaryElementParser, type SummaryElementStringifier } from "./summaryTypes.js";
import { VersionedSummarizer } from "./versionedSummarizer.js";
export interface ClonableSchemaAndPolicy extends SchemaAndPolicy {
    schema: TreeStoredSchemaRepository;
}
export interface SharedTreeCoreOptionsInternal extends CodecWriteOptions {
}
export interface EnrichmentConfig<TChange> {
    readonly enricher: ChangeEnricher<TChange>;
    readonly resubmitMachine?: ResubmitMachine<TChange>;
}
/**
 * Generic shared tree, which needs to be configured with indexes, field kinds and other configuration.
 */
export declare class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange> extends VersionedSummarizer<SharedTreeSummaryFormatVersion> implements WithBreakable, Summarizable {
    readonly breaker: Breakable;
    readonly sharedObject: IChannelView & IFluidLoadable;
    readonly serializer: IFluidSerializer;
    readonly submitLocalMessage: (content: unknown, localOpMetadata?: unknown) => void;
    protected readonly changeFamily: ChangeFamily<TEditor, TChange>;
    protected readonly idCompressor: IIdCompressor;
    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 enrichers;
    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: SharedTreeCoreOptionsInternal, changeFormatVersionForEditManager: DependentFormatVersion<EditManagerFormatVersion>, changeFormatVersionForMessage: DependentFormatVersion<MessageFormatVersion>, idCompressor: IIdCompressor, schema: TreeStoredSchemaRepository, schemaPolicy: SchemaPolicy, enrichmentConfig?: EnrichmentConfig<TChange>, getEditor?: () => TEditor);
    protected summarizeInternal(props: {
        stringify: SummaryElementStringifier;
        fullTree?: boolean;
        trackState?: boolean;
        telemetryContext?: ITelemetryContext;
        incrementalSummaryContext?: IExperimentalIncrementalSummaryContext;
        builder: SummaryTreeBuilder;
    }): void;
    protected loadInternal(services: IChannelStorageService, parse: SummaryElementParser): Promise<void>;
    summarizeCore(serializer: IFluidSerializer, telemetryContext?: ITelemetryContext, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext, fullTree?: boolean): ISummaryTreeWithStats;
    loadCore(services: IChannelStorageService): Promise<void>;
    private registerSharedBranch;
    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(branchId: BranchId, commit: GraphCommit<TChange>, schemaAndPolicy: ClonableSchemaAndPolicy, isResubmit: boolean): void;
    protected submitBranchCreation(branchId: BranchId): void;
    private submitMessage;
    /**
     * Process a bunch of messages from the runtime. SharedObject will call this method with a bunch of messages.
     */
    processMessagesCore(messagesCollection: IRuntimeMessageCollection): void;
    private processCommits;
    getLocalBranch(): SharedTreeBranch<TEditor, TChange>;
    getSharedBranchIds(): string[];
    createSharedBranch(): string;
    protected addBranch(branchId: BranchId): void;
    getSharedBranch(branchId: BranchId): SharedTreeBranch<TEditor, TChange>;
    didAttach(): void;
    reSubmitCore(content: JsonCompatibleReadOnly, localOpMetadata: unknown): void;
    rollback(content: JsonCompatibleReadOnly, localOpMetadata: unknown): void;
    applyStashedOp(content: JsonCompatibleReadOnly): void;
    protected registerSharedBranchForEditing(branchId: BranchId, enricher: ChangeEnricher<TChange>, resubmitMachine?: ResubmitMachine<TChange>): void;
    private getResubmitMachine;
    private tryGetResubmitMachine;
    getCommitEnricher(branchId: BranchId): BranchCommitEnricher<TChange>;
    private getEnricherState;
    private tryGetEnricherState;
}
//# sourceMappingURL=sharedTreeCore.d.ts.map