"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Format = exports.EncodedRootsForRevision = exports.RootRanges = exports.RootRange = exports.DetachId = exports.version = void 0;
const typebox_1 = require("@sinclair/typebox");
const index_js_1 = require("../../util/index.js");
const index_js_2 = require("../rebase/index.js");
exports.version = 1.0;
/**
 * The ID of a detached node. Is not globally unique on.
 * A `RevisionTag` + `DetachId` pair is globally unique and eventually consistent across clients.
 */
exports.DetachId = typebox_1.Type.Number({ multipleOf: 1 });
/**
 * The ID of a root node in the forest associated with the owning checkout. Is unique for that forest.
 * Is not consistent across clients.
 */
const ForestRootIdSchema = (0, index_js_1.brandedNumberType)({ minimum: -1, multipleOf: 1 });
/**
 * A mapping from a range of the detached node IDs the corresponding range root IDs.
 * The detached node IDs need to be qualified with a revision (stored in the containing `EncodedRootsForRevision`).
 * Note: the length of the range (currently always 1) can be looked up in the forest.
 */
exports.RootRange = typebox_1.Type.Tuple([
    // ID for the first detached node
    exports.DetachId,
    // ID for the first root node
    ForestRootIdSchema,
]);
exports.RootRanges = typebox_1.Type.Array(exports.RootRange);
/**
 * For all the roots detached in a revision, represents a mapping from the detached node ID to corresponding root ID.
 */
exports.EncodedRootsForRevision = typebox_1.Type.Union([
    // Used to represent a revision in which more than one node were detached
    typebox_1.Type.Tuple([index_js_2.RevisionTagSchema, exports.RootRanges]),
    // Used to represent a revision in which a single node was detached
    typebox_1.Type.Tuple([index_js_2.RevisionTagSchema, exports.DetachId, ForestRootIdSchema]),
]);
exports.Format = typebox_1.Type.Object({
    version: typebox_1.Type.Literal(exports.version),
    data: typebox_1.Type.Array(exports.EncodedRootsForRevision),
    maxId: ForestRootIdSchema,
}, { additionalProperties: false });
//# sourceMappingURL=detachedFieldIndexFormat.js.map