/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { unreachableCase } from "@fluidframework/core-utils/internal";
import { makeCodecFamily, makeVersionDispatchingCodec, } from "../codec/index.js";
import { brand } from "../util/index.js";
import { makeV1ToV4CodecWithVersion } from "./messageCodecV1ToV4.js";
import { makeV5CodecWithVersion } from "./messageCodecV5.js";
export function makeMessageCodec(changeCodecs, dependentChangeFormatVersion, revisionTagCodec, options, writeVersion = brand(1)) {
    const family = makeMessageCodecs(changeCodecs, dependentChangeFormatVersion, revisionTagCodec, options);
    return makeVersionDispatchingCodec(family, { ...options, writeVersion });
}
/**
 * @privateRemarks Exported for testing.
 */
export function makeMessageCodecs(changeCodecs, dependentChangeFormatVersion, revisionTagCodec, options) {
    const registry = Array.from(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,
                    makeV1ToV4CodecWithVersion(changeCodec, revisionTagCodec, options, version ?? 1),
                ];
            case 5:
                return [
                    version,
                    makeV5CodecWithVersion(changeCodec, revisionTagCodec, options, version),
                ];
            default:
                unreachableCase(version);
        }
    });
    return makeCodecFamily(registry);
}
export const messageFormatVersions = new Set([
    brand(undefined),
    brand(1),
    brand(2),
    brand(3),
    brand(4),
    brand(5),
]);
export function getCodecTreeForMessageFormatWithChange(version, changeFormat) {
    return {
        name: "Message",
        version,
        children: [changeFormat],
    };
}
//# sourceMappingURL=messageCodecs.js.map