/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { assert } from "@fluidframework/core-utils/internal";
import { makeVersionedValidatedCodec } from "../../codec/index.js";
import { Format } from "./format.js";
export function makeForestSummarizerCodec(options, fieldBatchCodec) {
    const inner = fieldBatchCodec;
    return makeVersionedValidatedCodec(options, new Set([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);
            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;
        },
    });
}
//# sourceMappingURL=codec.js.map