/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { assert } from "@fluidframework/core-utils/internal";
import { makeCodecFamily, withSchemaValidation, } from "../../codec/index.js";
import { makeSchemaCodec } from "../schema-index/index.js";
import { EncodedSchemaChange } from "./schemaChangeFormat.js";
export function makeSchemaChangeCodecs(options) {
    return makeCodecFamily([[1, makeSchemaChangeCodec(options)]]);
}
function makeSchemaChangeCodec({ jsonValidator: validator, }) {
    const schemaCodec = makeSchemaCodec({ jsonValidator: validator });
    const schemaChangeCodec = {
        encode: (schemaChange) => {
            assert(!schemaChange.isInverse, 0x933 /* Inverse schema changes should never be transmitted */);
            return {
                new: schemaCodec.encode(schemaChange.schema.new),
                old: schemaCodec.encode(schemaChange.schema.old),
            };
        },
        decode: (encoded) => {
            return {
                schema: {
                    new: schemaCodec.decode(encoded.new),
                    old: schemaCodec.decode(encoded.old),
                },
                isInverse: false,
            };
        },
        encodedSchema: EncodedSchemaChange,
    };
    return withSchemaValidation(EncodedSchemaChange, schemaChangeCodec, validator);
}
//# sourceMappingURL=schemaChangeCodecs.js.map