"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCodecTreeForMessageFormatWithChange = exports.makeMessageCodecBuilder = exports.messageCodecName = void 0;
const internal_1 = require("@fluidframework/runtime-utils/internal");
const index_js_1 = require("../codec/index.js");
const messageCodecV1ToV4_js_1 = require("./messageCodecV1ToV4.js");
const messageCodecVSharedBranches_js_1 = require("./messageCodecVSharedBranches.js");
const messageFormat_js_1 = require("./messageFormat.js");
/**
 * Codec name used to identify the message codec, see {@link makeMessageCodecBuilder}.
 */
exports.messageCodecName = "Message";
/**
 * Creates a {@link ClientVersionDispatchingCodecBuilder} for encoding/decoding messages.
 */
function makeMessageCodecBuilder() {
    // See MessageFormatVersion and its members for documentation on what changed in each version.
    const versions = [
        // The "undefined" wire format (no version field) is discontinued.
        (0, index_js_1.makeDiscontinuedCodecAndSchema)(undefined, "2.73.0"),
        (0, index_js_1.makeDiscontinuedCodecAndSchema)(messageFormat_js_1.MessageFormatVersion.v1, "2.73.0"),
        (0, index_js_1.makeDiscontinuedCodecAndSchema)(messageFormat_js_1.MessageFormatVersion.v2, "2.73.0"),
        {
            minVersionForCollab: internal_1.lowestMinVersionForCollab,
            formatVersion: messageFormat_js_1.MessageFormatVersion.v3,
            codec: (options) => (0, messageCodecV1ToV4_js_1.makeV1ToV4CodecWithVersion)(options.changeCodecs.resolve(options.dependentChangeFormatVersion.lookup(messageFormat_js_1.MessageFormatVersion.v3)), options.revisionTagCodec, messageFormat_js_1.MessageFormatVersion.v3),
        },
        {
            minVersionForCollab: index_js_1.FluidClientVersion.v2_43,
            formatVersion: messageFormat_js_1.MessageFormatVersion.v4,
            codec: (options) => (0, messageCodecV1ToV4_js_1.makeV1ToV4CodecWithVersion)(options.changeCodecs.resolve(options.dependentChangeFormatVersion.lookup(messageFormat_js_1.MessageFormatVersion.v4)), options.revisionTagCodec, messageFormat_js_1.MessageFormatVersion.v4),
        },
        (0, index_js_1.makeDiscontinuedCodecAndSchema)(messageFormat_js_1.MessageFormatVersion.v5, "2.74.0"),
        {
            minVersionForCollab: index_js_1.FluidClientVersion.v2_80,
            formatVersion: messageFormat_js_1.MessageFormatVersion.v6,
            codec: (options) => (0, messageCodecV1ToV4_js_1.makeV1ToV4CodecWithVersion)(options.changeCodecs.resolve(options.dependentChangeFormatVersion.lookup(messageFormat_js_1.MessageFormatVersion.v6)), options.revisionTagCodec, messageFormat_js_1.MessageFormatVersion.v6),
        },
        {
            minVersionForCollab: undefined,
            formatVersion: messageFormat_js_1.MessageFormatVersion.vSharedBranches,
            codec: (options) => (0, messageCodecVSharedBranches_js_1.makeSharedBranchesCodecWithVersion)(options.changeCodecs.resolve(options.dependentChangeFormatVersion.lookup(messageFormat_js_1.MessageFormatVersion.vSharedBranches)), options.revisionTagCodec, messageFormat_js_1.MessageFormatVersion.vSharedBranches),
        },
    ];
    return index_js_1.ClientVersionDispatchingCodecBuilder.build(exports.messageCodecName, versions);
}
exports.makeMessageCodecBuilder = makeMessageCodecBuilder;
function getCodecTreeForMessageFormatWithChange(clientVersion, changeFormat) {
    const builder = makeMessageCodecBuilder();
    return {
        ...builder.getCodecTree(clientVersion),
        children: [changeFormat],
    };
}
exports.getCodecTreeForMessageFormatWithChange = getCodecTreeForMessageFormatWithChange;
//# sourceMappingURL=messageCodecs.js.map