"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.mapRootChanges = exports.changeAtomFromDetachedNodeId = exports.nodeIdFromChangeAtom = void 0;
const index_js_1 = require("../core/index.js");
const index_js_2 = require("../util/index.js");
function nodeIdFromChangeAtom(changeAtom) {
    return (0, index_js_1.makeDetachedNodeId)(changeAtom.revision, changeAtom.localId);
}
exports.nodeIdFromChangeAtom = nodeIdFromChangeAtom;
function changeAtomFromDetachedNodeId(changeAtom) {
    return (0, index_js_1.makeChangeAtomId)((0, index_js_2.brand)(changeAtom.minor), changeAtom.major);
}
exports.changeAtomFromDetachedNodeId = changeAtomFromDetachedNodeId;
/**
 * Converts a `Delta.Root` whose tree content is represented with by `TIn` instances
 * into a `Delta.Root`whose tree content is represented with by `TOut` instances.
 *
 * This function is useful for converting `Delta`s that represent tree content with cursors
 * into `Delta`s that represent tree content with a deep-comparable representation of the content.
 * See {@link assertDeltaEqual}.
 * @param root - The delta to convert. Not mutated.
 * @param func - The functions used to map tree content.
 */
function mapRootChanges(root, func) {
    const out = {};
    if (root.fields !== undefined) {
        out.fields = root.fields;
    }
    if (root.build !== undefined) {
        out.build = root.build.map(({ id, trees }) => ({
            id,
            trees: func(trees),
        }));
    }
    if (root.global !== undefined) {
        out.global = root.global.map(({ id, fields }) => ({
            id,
            fields,
        }));
    }
    if (root.rename !== undefined) {
        out.rename = root.rename.map(({ count, oldId, newId }) => ({
            count,
            oldId,
            newId,
        }));
    }
    return out;
}
exports.mapRootChanges = mapRootChanges;
//# sourceMappingURL=deltaUtils.js.map