"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.editManagerFormatVersions = exports.supportedEditManagerFormatVersions = exports.EditManagerFormatVersion = exports.EncodedSharedBranch = exports.SummarySessionBranch = exports.SequencedCommit = void 0;
const typebox_1 = require("@sinclair/typebox");
const index_js_1 = require("../core/index.js");
const index_js_2 = require("../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) => typebox_1.Type.Object({
    revision: index_js_1.RevisionTagSchema,
    change: tChange,
    sessionId: index_js_1.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) => typebox_1.Type.Composite([CommitBase(tChange)], noAdditionalProps);
const SeqNumber = (0, index_js_2.brandedNumberType)({ multipleOf: 1 });
const SequenceId = typebox_1.Type.Object({
    sequenceNumber: SeqNumber,
    indexInBatch: typebox_1.Type.Optional(typebox_1.Type.Number({ multipleOf: 1, minimum: 0 })),
});
const SequencedCommit = (tChange) => typebox_1.Type.Composite([CommitBase(tChange), SequenceId], noAdditionalProps);
exports.SequencedCommit = SequencedCommit;
const SummarySessionBranch = (tChange) => typebox_1.Type.Object({
    base: index_js_1.RevisionTagSchema,
    commits: typebox_1.Type.Array(Commit(tChange)),
}, noAdditionalProps);
exports.SummarySessionBranch = SummarySessionBranch;
const EncodedSharedBranch = (tChange) => typebox_1.Type.Object({
    id: typebox_1.Type.Optional(typebox_1.Type.Number()),
    name: typebox_1.Type.Optional(typebox_1.Type.String()),
    session: typebox_1.Type.Optional(index_js_1.SessionIdSchema),
    author: typebox_1.Type.Optional(typebox_1.Type.String()),
    base: typebox_1.Type.Optional(index_js_1.RevisionTagSchema),
    trunk: typebox_1.Type.Array((0, exports.SequencedCommit)(tChange)),
    peers: typebox_1.Type.Array(typebox_1.Type.Tuple([index_js_1.SessionIdSchema, (0, exports.SummarySessionBranch)(tChange)])),
}, noAdditionalProps);
exports.EncodedSharedBranch = EncodedSharedBranch;
/**
 * The format version for the EditManager.
 */
exports.EditManagerFormatVersion = (0, index_js_2.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",
});
exports.supportedEditManagerFormatVersions = new Set([
    exports.EditManagerFormatVersion.v3,
    exports.EditManagerFormatVersion.v4,
    exports.EditManagerFormatVersion.v6,
    exports.EditManagerFormatVersion.vSharedBranches,
]);
exports.editManagerFormatVersions = new Set(Object.values(exports.EditManagerFormatVersion));
/* eslint-enable @typescript-eslint/explicit-function-return-type */
//# sourceMappingURL=editManagerFormatCommons.js.map