"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.ForestRootIdSchema = exports.DetachId = void 0;
const typebox_1 = require("@sinclair/typebox");
const index_js_1 = require("../../util/index.js");
/**
 * 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.
 */
exports.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
    exports.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.
 */
// Return type is intentionally derived.
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const EncodedRootsForRevision = (tRevisionTag) => typebox_1.Type.Union([
    // Used to represent a revision in which more than one node were detached
    typebox_1.Type.Tuple([tRevisionTag, exports.RootRanges]),
    // Used to represent a revision in which a single node was detached
    typebox_1.Type.Tuple([tRevisionTag, exports.DetachId, exports.ForestRootIdSchema]),
]);
exports.EncodedRootsForRevision = EncodedRootsForRevision;
const Format = (tVersion, tRevisionTag) => typebox_1.Type.Object({
    version: typebox_1.Type.Literal(tVersion),
    data: typebox_1.Type.Array((0, exports.EncodedRootsForRevision)(tRevisionTag)),
    maxId: exports.ForestRootIdSchema,
}, { additionalProperties: false });
exports.Format = Format;
//# sourceMappingURL=detachedFieldIndexFormatCommon.js.map