"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var conformance_exports = {};
__export(conformance_exports, {
  createConformanceValidator: () => createConformanceValidator
});
module.exports = __toCommonJS(conformance_exports);
var import_conformance_compiler = require("./conformance-compiler.js");
var import_peer_forwarding = require("./peer-forwarding.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function createConformanceValidator(schema, supervisor, nextValidator) {
  const validate = (0, import_conformance_compiler.astToFunction)(schema, supervisor);
  if (!validate && !nextValidator) {
    return void 0;
  }
  return (value, session, location) => {
    const cfg = location.config?.supervision;
    if (cfg?.validate === false) {
      return;
    }
    if (cfg?.conformance !== false) {
      try {
        validate?.(value, session, location);
      } catch (e) {
        if (!(0, import_peer_forwarding.forwardValidationToPeer)(session, e)) {
          throw e;
        }
      }
    }
    if (value !== void 0) {
      nextValidator?.(value, session, location);
    }
  };
}
//# sourceMappingURL=conformance.js.map
