"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.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()]);
const EncodedOptionalChangeset = (tNodeChange) => typebox_1.Type.Object({
    // Moves between detached fields.
    // These entries should not be interpreted as "applied one after the other", but rather as
    // "applied simultaneously". As such, this list should not contain duplicated src or dst entries.
    m: typebox_1.Type.Optional(typebox_1.Type.Array(EncodedMove)),
    // Nested changes
    c: typebox_1.Type.Optional(EncodedChildChanges(tNodeChange)),
    // How to replace the current value of the field.
    r: typebox_1.Type.Optional(EncodedReplace),
}, 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.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 EncodedMove = typebox_1.Type.Tuple([index_js_1.EncodedChangeAtomId, index_js_1.EncodedChangeAtomId]);
const EncodedReplace = typebox_1.Type.Object({
    // Whether the field is empty in the input context of this change.
    e: typebox_1.Type.Boolean(),
    // The ID for the node to put in this field, or undefined if the field should be emptied.
    // Will be "self" when the intention is to keep the current node in this field.
    s: typebox_1.Type.Optional(exports.EncodedRegisterId),
    // An ID to associate with the node (if any) which is detached by this edit.
    d: index_js_1.EncodedChangeAtomId,
}, noAdditionalProps);
//# sourceMappingURL=optionalFieldChangeFormatV2.js.map