"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.EncodedOptionalFieldChange = exports.EncodedNodeUpdate = void 0;
const typebox_1 = require("@sinclair/typebox");
const core_1 = require("../../core");
const modular_schema_1 = require("../modular-schema");
const noAdditionalProps = { additionalProperties: false };
const EncodedNodeUpdate = (tNodeChange) => typebox_1.Type.Union([
    typebox_1.Type.Object({
        set: core_1.EncodedJsonableTree,
        buildId: modular_schema_1.EncodedChangeAtomId,
        changes: typebox_1.Type.Optional(tNodeChange),
    }, noAdditionalProps),
    typebox_1.Type.Object({
        revert: modular_schema_1.EncodedChangeAtomId,
        changes: typebox_1.Type.Optional(tNodeChange),
    }, noAdditionalProps),
]);
exports.EncodedNodeUpdate = EncodedNodeUpdate;
/**
 * Note: TS doesn't easily support extracting a generic function's return type until 4.7:
 * https://github.com/microsoft/TypeScript/pull/47607
 * This type is a workaround and can be removed once we're on a version of typescript which
 * supports expressions more like:
 * `Static<ReturnType<typeof EncodedNodeUpdate<Schema>>>`
 */
class Wrapper {
    encodedNodeUpdate(e) {
        return (0, exports.EncodedNodeUpdate)(e);
    }
    encodedOptionalFieldChange(e) {
        return (0, exports.EncodedOptionalFieldChange)(e);
    }
    encodedOptionalChangeset(e) {
        return (0, exports.EncodedOptionalChangeset)(e);
    }
}
const EncodedOptionalFieldChange = (tNodeChange) => typebox_1.Type.Object({
    /**
     * Uniquely identifies, in the scope of the changeset, the change made to the field.
     * Globally unique across all changesets when paired with the changeset's revision tag.
     */
    id: modular_schema_1.ChangesetLocalIdSchema,
    /**
     * When populated, indicates the revision that this field change is associated with.
     * Is left undefined when the revision is the same as that of the whole changeset
     * (which would also be undefined in the case of an anonymous changeset).
     */
    revision: typebox_1.Type.Optional(core_1.RevisionTagSchema),
    /**
     * The new content for the trait. If undefined, the trait will be cleared.
     */
    newContent: typebox_1.Type.Optional((0, exports.EncodedNodeUpdate)(tNodeChange)),
    /**
     * Whether the field was empty in the state this change is based on.
     */
    wasEmpty: typebox_1.Type.Boolean(),
}, noAdditionalProps);
exports.EncodedOptionalFieldChange = EncodedOptionalFieldChange;
const EncodedOptionalChangeset = (tNodeChange) => typebox_1.Type.Object({
    fieldChange: typebox_1.Type.Optional((0, exports.EncodedOptionalFieldChange)(tNodeChange)),
    childChanges: typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.Tuple([
        typebox_1.Type.Union([modular_schema_1.EncodedChangeAtomId, typebox_1.Type.Literal("self")]),
        tNodeChange,
    ]))),
}, noAdditionalProps);
exports.EncodedOptionalChangeset = EncodedOptionalChangeset;
//# sourceMappingURL=defaultFieldChangeFormat.js.map