/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { Type } from "@sinclair/typebox";
import { brandedNumberType } from "../util";
import { SessionIdSchema, RevisionTagSchema, } from "../core";
const noAdditionalProps = { additionalProperties: false };
const CommitBase = (tChange) => Type.Object({
    revision: RevisionTagSchema,
    change: tChange,
    sessionId: SessionIdSchema,
});
/**
 * @privateRemarks Commits are generally encoded from `GraphCommit`s, which often contain extra data.
 * This `noAdditionalProps` is especially important in that light.
 */
const Commit = (tChange) => Type.Composite([CommitBase(tChange)], noAdditionalProps);
const SeqNumber = brandedNumberType();
export const sequenceIdComparator = (a, b) => a.sequenceNumber !== b.sequenceNumber
    ? a.sequenceNumber - b.sequenceNumber
    : (a.indexInBatch ?? 0) - (b.indexInBatch ?? 0);
export const equalSequenceIds = (a, b) => sequenceIdComparator(a, b) === 0;
export const minSequenceId = (a, b) => sequenceIdComparator(a, b) < 0 ? a : b;
const SequencedCommit = (tChange) => Type.Composite([
    CommitBase(tChange),
    Type.Object({
        sequenceNumber: SeqNumber,
        indexInBatch: Type.Optional(Type.Number()),
    }),
], noAdditionalProps);
const SummarySessionBranch = (tChange) => Type.Object({
    base: RevisionTagSchema,
    commits: Type.Array(Commit(tChange)),
}, noAdditionalProps);
export const EncodedEditManager = (tChange) => Type.Object({
    trunk: Type.Array(SequencedCommit(tChange)),
    branches: Type.Array(Type.Tuple([SessionIdSchema, SummarySessionBranch(tChange)])),
}, noAdditionalProps);
//# sourceMappingURL=editManagerFormat.js.map