/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { withSchemaValidation, } from "../../codec/index.js";
import { TreeCompressionStrategy } from "../treeCompressionUtils.js";
import { encodeChange, decodeChange, getFieldChangesetCodecs, } from "./modularChangeCodecV1.js";
import { EncodedModularChangesetV2 } from "./modularChangeFormatV2.js";
export function makeModularChangeCodecV2(fieldKinds, revisionTagCodec, fieldsCodec, codecOptions, chunkCompressionStrategy = TreeCompressionStrategy.Compressed) {
    const fieldChangesetCodecs = getFieldChangesetCodecs(fieldKinds, revisionTagCodec, codecOptions);
    const modularChangeCodec = {
        encode: (change, context) => {
            const encoded = encodeChange(change, context, fieldChangesetCodecs, revisionTagCodec, fieldsCodec, chunkCompressionStrategy);
            encoded.noChangeConstraint = change.noChangeConstraint;
            return encoded;
        },
        decode: (encodedChange, context) => {
            const decoded = decodeChange(encodedChange, context, fieldKinds, fieldChangesetCodecs, revisionTagCodec, fieldsCodec, chunkCompressionStrategy);
            if (encodedChange.noChangeConstraint !== undefined) {
                decoded.noChangeConstraint = encodedChange.noChangeConstraint;
            }
            return decoded;
        },
    };
    return withSchemaValidation(EncodedModularChangesetV2, modularChangeCodec, codecOptions.jsonValidator);
}
//# sourceMappingURL=modularChangeCodecV2.js.map