/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { AnchorSet, ChangeFamily, ChangeFamilyEditor, GraphCommit, IRepairDataStoreProvider, RepairDataStore, UndoRedoManager } from "../core";
import { EventEmitter } from "../events";
import { TransactionResult } from "../util";
/**
 * Describes a change to a `SharedTreeBranch`. Various operations can mutate the head of the branch;
 * this change format describes each in terms of the "removed commits" (all commits which were present
 * on the branch before the operation but are no longer present after) and the "new commits" (all
 * commits which are present on the branch after the operation that were not present before). Each of
 * the following event types also provides a `change` which contains the net change to the branch
 * (or is undefined if there was no net change):
 * * Append - when one or more commits are appended to the head of the branch, for example via
 * a change applied by the branch's editor, or as a result of merging another branch into this one
 * * Rollback - when one or more commits are removed from the head of the branch. This occurs
 * when a transaction is aborted, and all commits in that transaction are removed.
 * * Rebase - when this branch is rebased over another branch. In this case, commits on the source
 * branch are removed and replaced with new, rebased versions
 */
export declare type SharedTreeBranchChange<TChange> = {
    type: "append";
    change: TChange | undefined;
    newCommits: GraphCommit<TChange>[];
} | {
    type: "rollback";
    change: TChange | undefined;
    removedCommits: GraphCommit<TChange>[];
} | {
    type: "rebase";
    change: TChange | undefined;
    removedCommits: GraphCommit<TChange>[];
    newCommits: GraphCommit<TChange>[];
};
/**
 * The events emitted by a `SharedTreeBranch`
 */
export interface SharedTreeBranchEvents<TEditor extends ChangeFamilyEditor, TChange> {
    /**
     * Fired anytime the head of this branch changes.
     * @param change - the change to this branch's state and commits
     */
    change(change: SharedTreeBranchChange<TChange>): void;
    /**
     * Fired when this branch forks
     * @param fork - the new branch that forked off of this branch
     */
    fork(fork: SharedTreeBranch<TEditor, TChange>): void;
    /**
     * Fired after this branch is disposed
     */
    dispose(): void;
}
/**
 * A branch of changes that can be applied to a SharedTree.
 */
export declare class SharedTreeBranch<TEditor extends ChangeFamilyEditor, TChange> extends EventEmitter<SharedTreeBranchEvents<TEditor, TChange>> {
    private head;
    private readonly sessionId;
    readonly changeFamily: ChangeFamily<TEditor, TChange>;
    undoRedoManager: UndoRedoManager<TChange, TEditor>;
    private readonly anchors?;
    readonly editor: TEditor;
    private readonly transactions;
    private disposed;
    /**
     * Construct a new branch.
     * @param head - the head of the branch
     * @param sessionId - the session ID used to author commits made by this branch
     * @param rebaser - the rebaser used for rebasing and merging commits across branches
     * @param changeFamily - determines the set of changes that this branch can commit
     * @param undoRedoManager - the undo/redo manager used to track undoable commits. undoRedoManager.getHead
     * can not be called within this constructor.
     * @param anchors - an optional set of anchors that this branch will rebase whenever the branch head changes
     */
    constructor(head: GraphCommit<TChange>, sessionId: string, changeFamily: ChangeFamily<TEditor, TChange>, undoRedoManager: UndoRedoManager<TChange, TEditor>, anchors?: AnchorSet | undefined);
    private applyChange;
    /**
     * @returns the commit at the head of this branch.
     */
    getHead(): GraphCommit<TChange>;
    startTransaction(repairStore?: RepairDataStore): void;
    commitTransaction(): TransactionResult.Commit;
    abortTransaction(): TransactionResult.Abort;
    isTransacting(): boolean;
    private popTransaction;
    /**
     * 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;
    /**
     * Spawn a new branch that is based off of the current state of this branch.
     * Changes made to the new branch will not be applied to this branch until the new branch is merged back in.
     * @param anchors - an optional set of anchors that the new branch is responsible for rebasing
     */
    fork(repairDataStoreProvider?: IRepairDataStoreProvider, anchors?: AnchorSet): SharedTreeBranch<TEditor, TChange>;
    /**
     * Rebase the changes that have been applied to this branch over all the divergent changes in the given branch.
     * After this operation completes, this branch will be based off of `branch`.
     * @param branch - the head of the branch to rebase onto
     * @param undoRedoManager - the undo redo manager of the branch to rebase onto. This is necessary for updating the
     * undo redo manager of this branch.
     * @returns the net change to this branch
     */
    rebaseOnto(branch: GraphCommit<TChange>, undoRedoManager: UndoRedoManager<TChange, TEditor>): void;
    /**
     * Apply all the divergent changes on the given branch to this branch.
     * @returns the net change to this branch
     */
    merge(branch: SharedTreeBranch<TEditor, TChange>): void;
    /** Rebase `branchHead` onto `onto`, but return undefined if nothing changed */
    private rebaseBranch;
    /**
     * Dispose this branch, freezing its state.
     * Attempts to further mutate or dispose the branch will error.
     */
    dispose(): void;
    private emitAndRebaseAnchors;
    private assertNotDisposed;
}
//# sourceMappingURL=branch.d.ts.map