/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { Type } from "@sinclair/typebox";
import { RevisionTagSchema, SessionIdSchema, } from "../core/index.js";
import { brandedNumberType, strictEnum } from "../util/index.js";
const noAdditionalProps = { additionalProperties: false };
// Many of the return types in this module are intentionally derived, rather than explicitly specified.
/* eslint-disable @typescript-eslint/explicit-function-return-type */
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({ multipleOf: 1 });
const SequenceId = Type.Object({
    sequenceNumber: SeqNumber,
    indexInBatch: Type.Optional(Type.Number({ multipleOf: 1, minimum: 0 })),
});
export const SequencedCommit = (tChange) => Type.Composite([CommitBase(tChange), SequenceId], noAdditionalProps);
export const SummarySessionBranch = (tChange) => Type.Object({
    base: RevisionTagSchema,
    commits: Type.Array(Commit(tChange)),
}, noAdditionalProps);
export const EncodedSharedBranch = (tChange) => Type.Object({
    id: Type.Optional(Type.Number()),
    name: Type.Optional(Type.String()),
    session: Type.Optional(SessionIdSchema),
    author: Type.Optional(Type.String()),
    base: Type.Optional(RevisionTagSchema),
    trunk: Type.Array(SequencedCommit(tChange)),
    peers: Type.Array(Type.Tuple([SessionIdSchema, SummarySessionBranch(tChange)])),
}, noAdditionalProps);
/**
 * The format version for the EditManager.
 */
export const EditManagerFormatVersion = strictEnum("editManager.FormatVersion", {
    /**
     * Introduced and retired prior to 2.0.
     * Reading and writing capability removed in 2.73.0.
     */
    v1: 1,
    /**
     * Introduced and retired prior to 2.0.
     * Reading and writing capability removed in 2.73.0.
     */
    v2: 2,
    /**
     * Introduced prior to 2.0 and used beyond.
     * Reading capability must be maintained for backwards compatibility.
     * Writing capability needs to be maintained so long as {@link lowestMinVersionForCollab} is less than 2.2.0.
     */
    v3: 3,
    /**
     * Introduced in 2.2.0.
     * Was inadvertently made usable for writing in 2.43.0 (through configuredSharedTree) and remains available.
     * Reading capability must be maintained for backwards compatibility.
     * Writing capability could be dropped in favor of {@link EditManagerFormatVersion.v3},
     * but doing so would make the pattern of writable versions more complex and gain little
     * because most of the logic for this format is shared with {@link EditManagerFormatVersion.v3}.
     */
    v4: 4,
    /**
     * This version number was used internally for testing shared branches.
     * This format was never made stable.
     * This version number is kept here solely to avoid reusing the number: it is not supported for either reading or writing.
     * @deprecated Use {@link EditManagerFormatVersion.vSharedBranches} for testing shared branches.
     */
    v5: 5,
    /**
     * Introduced and made available for writing in 2.80.0
     * Adds support for "no change" constraints.
     */
    v6: 6,
    /**
     * Not yet released.
     * Only used for testing shared branches.
     */
    vSharedBranches: "shared-branches|v0.1",
});
export const supportedEditManagerFormatVersions = new Set([
    EditManagerFormatVersion.v3,
    EditManagerFormatVersion.v4,
    EditManagerFormatVersion.v6,
    EditManagerFormatVersion.vSharedBranches,
]);
export const editManagerFormatVersions = new Set(Object.values(EditManagerFormatVersion));
/* eslint-enable @typescript-eslint/explicit-function-return-type */
//# sourceMappingURL=editManagerFormatCommons.js.map