"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Format = exports.EncodedRootsForRevision = exports.RootRanges = exports.RootRange = exports.ForestRootIdSchema = exports.DetachId = exports.DetachedFieldIndexFormatVersion = void 0;
const Type = __importStar(require("@sinclair/typebox"));
const index_js_1 = require("../../util/index.js");
/**
 * The format version for the detached field index.
 */
exports.DetachedFieldIndexFormatVersion = (0, index_js_1.strictEnum)("DetachedFieldIndexFormatVersion", {
    v1: 1,
    v2: 2,
});
/**
 * 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 = 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 = Type.Tuple([
    // ID for the first detached node
    exports.DetachId,
    // ID for the first root node
    exports.ForestRootIdSchema,
]);
exports.RootRanges = 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) => Type.Union([
    // Used to represent a revision in which more than one node were detached
    Type.Tuple([tRevisionTag, exports.RootRanges]),
    // Used to represent a revision in which a single node was detached
    Type.Tuple([tRevisionTag, exports.DetachId, exports.ForestRootIdSchema]),
]);
exports.EncodedRootsForRevision = EncodedRootsForRevision;
const Format = (tVersion, tRevisionTag) => Type.Object({
    version: Type.Literal(tVersion),
    data: Type.Array((0, exports.EncodedRootsForRevision)(tRevisionTag)),
    maxId: exports.ForestRootIdSchema,
}, { additionalProperties: false });
exports.Format = Format;
//# sourceMappingURL=detachedFieldIndexFormatCommon.js.map