"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 internal_1 = require("@fluidframework/core-utils/internal");
const index_js_1 = require("../../codec/index.js");
const format_js_1 = require("./format.js");
function makeForestSummarizerCodec(options, fieldBatchCodec) {
    const inner = fieldBatchCodec;
    return (0, index_js_1.makeVersionedValidatedCodec)(options, new Set([1]), format_js_1.Format, {
        encode: (data, context) => {
            const keys = [];
            const fields = [];
            for (const [key, value] of data) {
                keys.push(key);
                fields.push(value);
            }
            return { keys, fields: inner.encode(fields, context), version: 1 };
        },
        decode: (data, context) => {
            const out = new Map();
            const fields = inner.decode(data.fields, context);
            (0, internal_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