/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { Type } from "@sinclair/typebox";
import { makeCodecFamily } from "../../codec/index.js";
import { EncodedGenericChangeset } from "./genericFieldKindFormat.js";
export function makeGenericChangeCodec(childCodec) {
    return makeCodecFamily([[0, makeV0Codec(childCodec)]]);
}
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: EncodedGenericChangeset(childCodec.encodedSchema ?? Type.Any()),
    };
}
//# sourceMappingURL=genericFieldKindCodecs.js.map