"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.EncodedOptionalChangeset = exports.EncodedBuild = exports.EncodedRegisterId = void 0;
const typebox_1 = require("@sinclair/typebox");
const index_js_1 = require("../modular-schema/index.js");
const noAdditionalProps = { additionalProperties: false };
// `null` signifies "self". Using undefined doesn't actually JSON round-trip conveniently, since
// undefined is converted to null when inside an array (which happens in e.g. the moves array).
exports.EncodedRegisterId = typebox_1.Type.Union([index_js_1.EncodedChangeAtomId, typebox_1.Type.Null()]);
exports.EncodedBuild = typebox_1.Type.Tuple([index_js_1.EncodedChangeAtomId]);
const EncodedOptionalChangeset = (tNodeChange) => typebox_1.Type.Object({
    // Subtrees being created. They start as detached.
    b: typebox_1.Type.Optional(typebox_1.Type.Array(exports.EncodedBuild)),
    // Subtrees being moved.
    m: EncodedMoves,
    // Nested changes
    c: EncodedChildChanges(tNodeChange),
    // Reserved ID for detaching the subtree from the field if it were to be populated.
    // Only specified when the field is empty.
    d: typebox_1.Type.Optional(exports.EncodedRegisterId),
}, noAdditionalProps);
exports.EncodedOptionalChangeset = EncodedOptionalChangeset;
const EncodedChildChanges = (tNodeChange) => 
// Changes to the children of the node that is in the specified register in the input context of this change.
typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.Tuple([exports.EncodedRegisterId, tNodeChange])));
// A list of triplets (source, destination, isNodeTargeting) each representing a move of a node
// from its current source register to a new destination register.
// If the move is node targeting then the intention is to move a specific node which happens to be in the source register.
// Otherwise the intention is to move whatever node happens to be in the source register.
// These entries should not be interpreted as "applied one after the other", but rather as "applied simultaneously".
// As such, changesets should not contain duplicated src or dst entries.
const EncodedMoves = typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.Tuple([exports.EncodedRegisterId, exports.EncodedRegisterId, typebox_1.Type.Optional(typebox_1.Type.Boolean())])));
//# sourceMappingURL=optionalFieldChangeFormatV0.js.map