"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeV1toV4andV6CodecWithVersion = void 0;
const index_js_1 = require("../util/index.js");
const editManagerCodecsCommons_js_1 = require("./editManagerCodecsCommons.js");
const editManagerFormatV1toV4_js_1 = require("./editManagerFormatV1toV4.js");
/**
 * Create the provided version of the {@link EditManager} codec (which encodes it's {@link SummaryData}).
 * @remarks
 * The changeCodec and revisionTagCodec are not explicitly versioned, so the exact right version of them must be provided here
 * or data will be incompatible.
 *
 * TODO: this file should be renamed as this is used for v6 as well.
 */
function makeV1toV4andV6CodecWithVersion(changeCodec, revisionTagCodec, version) {
    const schema = (0, editManagerFormatV1toV4_js_1.EncodedEditManager)(changeCodec.encodedSchema ?? index_js_1.JsonCompatibleReadOnlySchema);
    const codec = {
        schema,
        encode: (data, context) => {
            const mainBranch = (0, editManagerCodecsCommons_js_1.encodeSharedBranch)(changeCodec, revisionTagCodec, data.main, context, data.originator);
            const encoded = {
                trunk: mainBranch.trunk,
                branches: mainBranch.peers,
                version,
            };
            return encoded;
        },
        decode: (json, context) => {
            return {
                main: (0, editManagerCodecsCommons_js_1.decodeSharedBranch)(changeCodec, revisionTagCodec, {
                    trunk: json.trunk,
                    peers: json.branches,
                }, context, undefined),
            };
        },
    };
    return codec;
}
exports.makeV1toV4andV6CodecWithVersion = makeV1toV4andV6CodecWithVersion;
//# sourceMappingURL=editManagerCodecsV1toV4.js.map