"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeGenericChangeCodec = void 0;
const typebox_1 = require("@sinclair/typebox");
const index_js_1 = require("../../codec/index.js");
const genericFieldKindFormat_js_1 = require("./genericFieldKindFormat.js");
function makeGenericChangeCodec(childCodec) {
    return (0, index_js_1.makeCodecFamily)([[0, makeV0Codec(childCodec)]]);
}
exports.makeGenericChangeCodec = makeGenericChangeCodec;
function makeV0Codec(childCodec) {
    return {
        encode: (change, context) => {
            const encoded = change.map(({ index, nodeChange }) => [
                index,
                childCodec.encode(nodeChange, context),
            ]);
            return encoded;
        },
        decode: (encoded, context) => {
            return encoded.map(([index, nodeChange]) => ({
                index,
                nodeChange: childCodec.decode(nodeChange, context),
            }));
        },
        encodedSchema: (0, genericFieldKindFormat_js_1.EncodedGenericChangeset)(childCodec.encodedSchema ?? typebox_1.Type.Any()),
    };
}
//# sourceMappingURL=genericFieldKindCodecs.js.map