"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCodecTreeForDetachedFieldIndexFormat = exports.makeDetachedFieldIndexCodecFamily = exports.makeDetachedFieldIndexCodec = void 0;
const internal_1 = require("@fluidframework/runtime-utils/internal");
const index_js_1 = require("../../codec/index.js");
const detachedFieldIndexCodecV1_js_1 = require("./detachedFieldIndexCodecV1.js");
const detachedFieldIndexCodecV2_js_1 = require("./detachedFieldIndexCodecV2.js");
const detachedFieldIndexFormatCommon_js_1 = require("./detachedFieldIndexFormatCommon.js");
const index_js_2 = require("../../util/index.js");
/**
 * Convert a MinimumVersionForCollab to a version for detached field codecs.
 * @param clientVersion - The MinimumVersionForCollab to convert.
 * @returns The detached field codec version that corresponds to the provided MinimumVersionForCollab.
 */
function clientVersionToDetachedFieldVersion(clientVersion) {
    return (0, index_js_2.brand)((0, internal_1.getConfigForMinVersionForCollab)(clientVersion, {
        [internal_1.lowestMinVersionForCollab]: detachedFieldIndexFormatCommon_js_1.DetachedFieldIndexFormatVersion.v1,
        [index_js_1.FluidClientVersion.v2_52]: detachedFieldIndexFormatCommon_js_1.DetachedFieldIndexFormatVersion.v2,
    }));
}
function makeDetachedFieldIndexCodec(revisionTagCodec, options, idCompressor) {
    const family = makeDetachedFieldIndexCodecFamily(revisionTagCodec, options, idCompressor);
    return (0, index_js_1.makeVersionDispatchingCodec)(family, {
        ...options,
        writeVersion: clientVersionToDetachedFieldVersion(options.minVersionForCollab),
    });
}
exports.makeDetachedFieldIndexCodec = makeDetachedFieldIndexCodec;
function makeDetachedFieldIndexCodecFamily(revisionTagCodec, options, idCompressor) {
    return (0, index_js_1.makeCodecFamily)([
        [
            detachedFieldIndexFormatCommon_js_1.DetachedFieldIndexFormatVersion.v1,
            (0, detachedFieldIndexCodecV1_js_1.makeDetachedNodeToFieldCodecV1)(revisionTagCodec, options, idCompressor),
        ],
        [
            detachedFieldIndexFormatCommon_js_1.DetachedFieldIndexFormatVersion.v2,
            (0, detachedFieldIndexCodecV2_js_1.makeDetachedNodeToFieldCodecV2)(revisionTagCodec, options, idCompressor),
        ],
    ]);
}
exports.makeDetachedFieldIndexCodecFamily = makeDetachedFieldIndexCodecFamily;
function getCodecTreeForDetachedFieldIndexFormat(clientVersion) {
    return {
        name: "DetachedFieldIndex",
        version: clientVersionToDetachedFieldVersion(clientVersion),
    };
}
exports.getCodecTreeForDetachedFieldIndexFormat = getCodecTreeForDetachedFieldIndexFormat;
//# sourceMappingURL=detachedFieldIndexCodecs.js.map