"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeForestSummarizerCodec = void 0;
const core_utils_1 = require("@fluidframework/core-utils");
const codec_1 = require("../../codec");
const format_1 = require("./format");
function makeForestSummarizerCodec(options, fieldBatchCodec) {
    const inner = fieldBatchCodec;
    return (0, codec_1.makeVersionedValidatedCodec)(options, new Set([1]), format_1.Format, {
        encode: (data) => {
            const keys = [];
            const fields = [];
            for (const [key, value] of data) {
                keys.push(key);
                fields.push(value);
            }
            return { keys, fields: inner.encode(fields), version: 1 };
        },
        decode: (data) => {
            const out = new Map();
            const fields = inner.decode(data.fields);
            (0, core_utils_1.assert)(data.keys.length === fields.length, 0x891 /* mismatched lengths */);
            for (let index = 0; index < fields.length; index++) {
                out.set(data.keys[index], fields[index]);
            }
            return out;
        },
    });
}
exports.makeForestSummarizerCodec = makeForestSummarizerCodec;
//# sourceMappingURL=codec.js.map