"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.messageFormatVersions = exports.makeMessageCodecs = exports.makeMessageCodec = void 0;
const internal_1 = require("@fluidframework/core-utils/internal");
const index_js_1 = require("../codec/index.js");
const index_js_2 = require("../util/index.js");
const messageCodecV1ToV4_js_1 = require("./messageCodecV1ToV4.js");
const messageCodecV5_js_1 = require("./messageCodecV5.js");
function makeMessageCodec(changeCodecs, dependentChangeFormatVersion, revisionTagCodec, options, writeVersion = (0, index_js_2.brand)(1)) {
    const family = makeMessageCodecs(changeCodecs, dependentChangeFormatVersion, revisionTagCodec, options);
    return (0, index_js_1.makeVersionDispatchingCodec)(family, { ...options, writeVersion });
}
exports.makeMessageCodec = makeMessageCodec;
/**
 * @privateRemarks Exported for testing.
 */
function makeMessageCodecs(changeCodecs, dependentChangeFormatVersion, revisionTagCodec, options) {
    const registry = Array.from(exports.messageFormatVersions).map((version) => {
        const changeCodec = changeCodecs.resolve(dependentChangeFormatVersion.lookup(version)).json;
        switch (version) {
            case undefined:
            case 1:
            case 2:
            case 3:
            case 4:
                return [
                    version,
                    (0, messageCodecV1ToV4_js_1.makeV1ToV4CodecWithVersion)(changeCodec, revisionTagCodec, options, version ?? 1),
                ];
            case 5:
                return [
                    version,
                    (0, messageCodecV5_js_1.makeV5CodecWithVersion)(changeCodec, revisionTagCodec, options, version),
                ];
            default:
                (0, internal_1.unreachableCase)(version);
        }
    });
    return (0, index_js_1.makeCodecFamily)(registry);
}
exports.makeMessageCodecs = makeMessageCodecs;
exports.messageFormatVersions = new Set([
    (0, index_js_2.brand)(undefined),
    (0, index_js_2.brand)(1),
    (0, index_js_2.brand)(2),
    (0, index_js_2.brand)(3),
    (0, index_js_2.brand)(4),
    (0, index_js_2.brand)(5),
]);
function getCodecTreeForMessageFormatWithChange(version, changeFormat) {
    return {
        name: "Message",
        version,
        children: [changeFormat],
    };
}
exports.getCodecTreeForMessageFormatWithChange = getCodecTreeForMessageFormatWithChange;
//# sourceMappingURL=messageCodecs.js.map