/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { JsonCompatibleReadOnlySchema, } from "../util/index.js";
import { decodeSharedBranch, encodeSharedBranch } from "./editManagerCodecsCommons.js";
import { EncodedEditManager } from "./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.
 */
export function makeV1toV4andV6CodecWithVersion(changeCodec, revisionTagCodec, version) {
    const schema = EncodedEditManager(changeCodec.encodedSchema ?? JsonCompatibleReadOnlySchema);
    const codec = {
        schema,
        encode: (data, context) => {
            const mainBranch = encodeSharedBranch(changeCodec, revisionTagCodec, data.main, context, data.originator);
            const encoded = {
                trunk: mainBranch.trunk,
                branches: mainBranch.peers,
                version,
            };
            return encoded;
        },
        decode: (json, context) => {
            return {
                main: decodeSharedBranch(changeCodec, revisionTagCodec, {
                    trunk: json.trunk,
                    peers: json.branches,
                }, context, undefined),
            };
        },
    };
    return codec;
}
//# sourceMappingURL=editManagerCodecsV1toV4.js.map