"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 codec_1 = require("../../codec");
const genericFieldKindFormat_1 = require("./genericFieldKindFormat");
function makeGenericChangeCodec(childCodec) {
    return (0, codec_1.makeCodecFamily)([[0, makeV0Codec(childCodec)]]);
}
exports.makeGenericChangeCodec = makeGenericChangeCodec;
function makeV0Codec(childCodec) {
    return {
        encode: (change) => {
            const encoded = change.map(({ index, nodeChange }) => ({
                index,
                nodeChange: childCodec.encode(nodeChange),
            }));
            return encoded;
        },
        decode: (encoded) => {
            return encoded.map(({ index, nodeChange }) => ({
                index,
                nodeChange: childCodec.decode(nodeChange),
            }));
        },
        encodedSchema: (0, genericFieldKindFormat_1.EncodedGenericChangeset)(childCodec.encodedSchema ?? typebox_1.Type.Any()),
    };
}
//# sourceMappingURL=genericFieldKindCodecs.js.map