"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeModularChangeCodecV2 = void 0;
const index_js_1 = require("../../codec/index.js");
const treeCompressionUtils_js_1 = require("../treeCompressionUtils.js");
const modularChangeCodecV1_js_1 = require("./modularChangeCodecV1.js");
const modularChangeFormatV2_js_1 = require("./modularChangeFormatV2.js");
function makeModularChangeCodecV2(fieldKinds, revisionTagCodec, fieldsCodec, codecOptions, chunkCompressionStrategy = treeCompressionUtils_js_1.TreeCompressionStrategy.Compressed) {
    const fieldChangesetCodecs = (0, modularChangeCodecV1_js_1.getFieldChangesetCodecs)(fieldKinds, revisionTagCodec, codecOptions);
    const modularChangeCodec = {
        encode: (change, context) => {
            const encoded = (0, modularChangeCodecV1_js_1.encodeChange)(change, context, fieldChangesetCodecs, revisionTagCodec, fieldsCodec, chunkCompressionStrategy);
            encoded.noChangeConstraint = change.noChangeConstraint;
            return encoded;
        },
        decode: (encodedChange, context) => {
            const decoded = (0, modularChangeCodecV1_js_1.decodeChange)(encodedChange, context, fieldKinds, fieldChangesetCodecs, revisionTagCodec, fieldsCodec, chunkCompressionStrategy);
            if (encodedChange.noChangeConstraint !== undefined) {
                decoded.noChangeConstraint = encodedChange.noChangeConstraint;
            }
            return decoded;
        },
    };
    return (0, index_js_1.withSchemaValidation)(modularChangeFormatV2_js_1.EncodedModularChangesetV2, modularChangeCodec, codecOptions.jsonValidator);
}
exports.makeModularChangeCodecV2 = makeModularChangeCodecV2;
//# sourceMappingURL=modularChangeCodecV2.js.map