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