/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { Brand, RecursiveReadonly } from "../util";
import { AnchorSet, ChangeFamily, ChangeFamilyEditor, Delta, GraphCommit, ReadonlyRepairDataStore, RevisionTag, SessionId, SimpleDependee, UndoRedoManager, UndoRedoManagerCommitType } from "../core";
import { SharedTreeBranch } from ".";
export declare type SeqNumber = Brand<number, "edit-manager.SeqNumber">;
/**
 * Contains a single change to the `SharedTree` and associated metadata
 */
export interface Commit<TChangeset> extends Omit<GraphCommit<TChangeset>, "parent"> {
}
/**
 * A commit with a sequence number but no parentage; used for serializing the `EditManager` into a summary
 */
export interface SequencedCommit<TChangeset> extends Commit<TChangeset> {
    sequenceNumber: SeqNumber;
}
export declare const minimumPossibleSequenceNumber: SeqNumber;
/**
 * Represents a local branch of a document and interprets the effect on the document of adding sequenced changes,
 * which were based on a given session's branch, to the document history
 */
export declare class EditManager<TChangeset, TChangeFamily extends ChangeFamily<any, TChangeset>> extends SimpleDependee {
    readonly changeFamily: TChangeFamily;
    readonly localSessionId: SessionId;
    readonly localBranchUndoRedoManager: UndoRedoManager<TChangeset, any>;
    private readonly trunkUndoRedoManager;
    readonly anchors?: AnchorSet | undefined;
    /**
     * The head commit of the "trunk" branch. The trunk represents the list of received sequenced changes.
     */
    private trunk;
    /**
     * Branches are maintained to represent the local change list that the issuing client had
     * at the time of submitting the latest known edit on the branch.
     * This means the head commit of each branch is always in its original (non-rebased) form.
     */
    private readonly peerLocalBranches;
    /**
     * This branch holds the changes made by this client which have not yet been confirmed as sequenced changes.
     */
    private localBranch;
    /**
     * A map of local commit revisions to their undo redo manager commit types. This is stored so that
     * the trunk undo redo manager can properly track commits when they become sequenced.
     */
    private readonly localCommitTypes;
    /**
     * Tracks where on the trunk all registered branches are based. Each key is the sequence number of a commit on
     * the trunk, and the value is the set of all branches who have that commit as their common ancestor with the trunk.
     */
    private readonly trunkBranches;
    /**
     * The sequence number of the newest commit on the trunk that has been received by all peers
     */
    private minimumSequenceNumber;
    /**
     * A map from a sequence number to the commit in the trunk which has that sequence number
     */
    private readonly sequenceMap;
    /**
     * An immutable "origin" commit singleton on which the trunk is based.
     * This makes it possible to model the trunk in the same way as any other branch
     * (it branches off of a base commit) which simplifies some logic.
     */
    private readonly trunkBase;
    /**
     * @param localBranchUndoRedoManager - the {@link UndoRedoManager} associated with the local branch.
     * localBranchUndoRedoManager.getHead can not be called within this constructor.
     * @param trunkUndoRedoManager - the {@link UndoRedoManager} associated with the trunk.
     * trunkUndoRedoManager.getHead can not be called within this constructor.
     */
    constructor(changeFamily: TChangeFamily, localSessionId: SessionId, localBranchUndoRedoManager: UndoRedoManager<TChangeset, any>, trunkUndoRedoManager: UndoRedoManager<TChangeset, any>, anchors?: AnchorSet | undefined);
    /**
     * Make the given branch known to the `EditManager`. The `EditManager` will ensure that all registered
     * branches remain usable even as the minimum sequence number advances.
     * @param branch - the branch to register. All branches that fork from this branch, directly or transitively,
     * will also be registered.
     */
    registerBranch(branch: SharedTreeBranch<ChangeFamilyEditor, TChangeset>): void;
    /**
     * Advances the minimum sequence number, and removes all commits from the trunk which lie outside the collaboration window.
     * @param minimumSequenceNumber - the sequence number of the newest commit that all peers (including this one) have received and applied to their trunks
     */
    advanceMinimumSequenceNumber(minimumSequenceNumber: SeqNumber): void;
    /**
     * Examines the latest known minimum sequence number and the trunk bases of any registered branches to determine
     * if any commits on the trunk are unreferenced and unneeded for future computation; those found are evicted from the trunk.
     * @returns the number of commits that were removed from the trunk
     */
    private trimTrunk;
    isEmpty(): boolean;
    getSummaryData(): SummaryData<TChangeset>;
    loadSummaryData(data: SummaryData<TChangeset>): void;
    getTrunk(): readonly RecursiveReadonly<Commit<TChangeset>>[];
    getLastSequencedChange(): TChangeset;
    getTrunkHead(): GraphCommit<TChangeset>;
    /**
     * @returns the head commit of the local branch
     */
    getLocalBranchHead(): GraphCommit<TChangeset>;
    getLocalChanges(): readonly RecursiveReadonly<TChangeset>[];
    addSequencedChange(newCommit: Commit<TChangeset>, sequenceNumber: SeqNumber, referenceSequenceNumber: SeqNumber): Delta.Root;
    addLocalChange(revision: RevisionTag, change: TChangeset, rebaseAnchors?: boolean, undoRedoType?: UndoRedoManagerCommitType): Delta.Root;
    /**
     * Given a revision on the local branch, replace all commits after it with a single commit containing
     * an equivalent composition of changes.
     * @returns the new commit (which is now the head of the local branch)
     */
    squashLocalChanges(startRevision: RevisionTag): Commit<TChangeset>;
    /**
     * Given a revision on the local branch, remove all commits after it, and updates anchors accordingly.
     * @param startRevision - the revision on the local branch that will become the new head
     * @param repairStore - an optional repair data store to assist with generating inverses of the removed commits
     * @returns a delta that describes the change from rolling back all of the removed commits.
     */
    rollbackLocalChanges(startRevision: RevisionTag, repairStore?: ReadonlyRepairDataStore): Delta.Root;
    findLocalCommit(revision: RevisionTag): [commit: GraphCommit<TChangeset>, commitsAfter: GraphCommit<TChangeset>[]];
    private pushToTrunk;
    private pushToLocalBranch;
    private rebaseLocalBranchOverTrunk;
}
/**
 * A branch off of the trunk for use in summaries
 */
export interface SummarySessionBranch<TChangeset> {
    readonly base: RevisionTag;
    readonly commits: Commit<TChangeset>[];
}
/**
 * The in-memory data that summaries contain
 */
export interface SummaryData<TChangeset> {
    readonly trunk: readonly SequencedCommit<TChangeset>[];
    readonly branches: ReadonlyMap<SessionId, SummarySessionBranch<TChangeset>>;
}
//# sourceMappingURL=editManager.d.ts.map