"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Changeset = exports.CellMark = exports.MarkEffect = exports.CellId = void 0;
const typebox_1 = require("@sinclair/typebox");
const index_js_1 = require("../../codec/index.js");
const index_js_2 = require("../../core/index.js");
const index_js_3 = require("../modular-schema/index.js");
const noAdditionalProps = { additionalProperties: false };
const CellCount = typebox_1.Type.Number({ multipleOf: 1, minimum: 1 });
const MoveId = index_js_3.ChangesetLocalIdSchema;
const HasMoveId = typebox_1.Type.Object({ id: MoveId });
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const IdRange = typebox_1.Type.Tuple([index_js_3.ChangesetLocalIdSchema, CellCount]);
exports.CellId = index_js_3.EncodedChangeAtomId;
const HasRevisionTag = typebox_1.Type.Object({ revision: typebox_1.Type.Optional(index_js_2.RevisionTagSchema) });
const Insert = typebox_1.Type.Composite([HasMoveId, HasRevisionTag], noAdditionalProps);
const HasMoveFields = typebox_1.Type.Composite([
    HasMoveId,
    HasRevisionTag,
    typebox_1.Type.Object({ finalEndpoint: typebox_1.Type.Optional(index_js_3.EncodedChangeAtomId) }),
]);
const MoveIn = typebox_1.Type.Composite([HasMoveFields], noAdditionalProps);
const DetachFields = typebox_1.Type.Object({
    idOverride: typebox_1.Type.Optional(exports.CellId),
});
const Remove = typebox_1.Type.Composite([
    typebox_1.Type.Object({
        id: index_js_3.ChangesetLocalIdSchema,
    }),
    HasRevisionTag,
    DetachFields,
], noAdditionalProps);
const MoveOut = typebox_1.Type.Composite([HasMoveFields, DetachFields], noAdditionalProps);
const Attach = typebox_1.Type.Object({
    insert: typebox_1.Type.Optional(Insert),
    moveIn: typebox_1.Type.Optional(MoveIn),
}, index_js_1.unionOptions);
const Detach = typebox_1.Type.Object({
    remove: typebox_1.Type.Optional(Remove),
    moveOut: typebox_1.Type.Optional(MoveOut),
}, index_js_1.unionOptions);
const AttachAndDetach = typebox_1.Type.Object({
    attach: Attach,
    detach: Detach,
});
exports.MarkEffect = typebox_1.Type.Object({
    // Note: `noop` is encoded by omitting `effect` from the encoded cell mark, so is not included here.
    insert: typebox_1.Type.Optional(Insert),
    moveIn: typebox_1.Type.Optional(MoveIn),
    remove: typebox_1.Type.Optional(Remove),
    moveOut: typebox_1.Type.Optional(MoveOut),
    attachAndDetach: typebox_1.Type.Optional(AttachAndDetach),
}, index_js_1.unionOptions);
const CellMark = (tMark, tNodeChange) => typebox_1.Type.Object({
    // If undefined, indicates a Noop mark.
    effect: typebox_1.Type.Optional(tMark),
    cellId: typebox_1.Type.Optional(exports.CellId),
    changes: typebox_1.Type.Optional(tNodeChange),
    count: CellCount,
}, noAdditionalProps);
exports.CellMark = CellMark;
// Return type is intentionally derived.
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const Mark = (tNodeChange) => (0, exports.CellMark)(exports.MarkEffect, tNodeChange);
// Return type is intentionally derived.
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const Changeset = (tNodeChange) => typebox_1.Type.Array(Mark(tNodeChange));
exports.Changeset = Changeset;
//# sourceMappingURL=formatV2.js.map