"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.Changeset = exports.CellMark = exports.MarkEffect = exports.CellId = void 0;
const Type = __importStar(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 = Type.Number({ multipleOf: 1, minimum: 1 });
const MoveId = index_js_3.ChangesetLocalIdSchema;
const HasMoveId = Type.Object({ id: MoveId });
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const IdRange = Type.Tuple([index_js_3.ChangesetLocalIdSchema, CellCount]);
exports.CellId = index_js_3.EncodedChangeAtomId;
const HasRevisionTag = Type.Object({ revision: Type.Optional(index_js_2.RevisionTagSchema) });
const Insert = Type.Composite([HasMoveId, HasRevisionTag], noAdditionalProps);
const HasMoveFields = Type.Composite([
    HasMoveId,
    HasRevisionTag,
    Type.Object({ finalEndpoint: Type.Optional(index_js_3.EncodedChangeAtomId) }),
]);
const MoveIn = Type.Composite([HasMoveFields], noAdditionalProps);
const DetachFields = Type.Object({
    idOverride: Type.Optional(exports.CellId),
});
const Remove = Type.Composite([
    Type.Object({
        id: index_js_3.ChangesetLocalIdSchema,
    }),
    HasRevisionTag,
    DetachFields,
], noAdditionalProps);
const MoveOut = Type.Composite([HasMoveFields, DetachFields], noAdditionalProps);
const Attach = Type.Object({
    insert: Type.Optional(Insert),
    moveIn: Type.Optional(MoveIn),
}, index_js_1.unionOptions);
const Detach = Type.Object({
    remove: Type.Optional(Remove),
    moveOut: Type.Optional(MoveOut),
}, index_js_1.unionOptions);
const AttachAndDetach = Type.Object({
    attach: Attach,
    detach: Detach,
});
exports.MarkEffect = Type.Object({
    // Note: `noop` is encoded by omitting `effect` from the encoded cell mark, so is not included here.
    insert: Type.Optional(Insert),
    moveIn: Type.Optional(MoveIn),
    remove: Type.Optional(Remove),
    moveOut: Type.Optional(MoveOut),
    attachAndDetach: Type.Optional(AttachAndDetach),
}, index_js_1.unionOptions);
const CellMark = (tMark, tNodeChange) => Type.Object({
    // If undefined, indicates a Noop mark.
    effect: Type.Optional(tMark),
    cellId: Type.Optional(exports.CellId),
    changes: 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) => Type.Array(Mark(tNodeChange));
exports.Changeset = Changeset;
//# sourceMappingURL=formatV2.js.map