"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 Supervision_exports = {};
__export(Supervision_exports, {
  Supervision: () => Supervision
});
module.exports = __toCommonJS(Supervision_exports);
var import_Internal = require("../state/managed/Internal.js");
var import_SupervisionConfig = require("./SupervisionConfig.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function Supervision(target, nameOrMethod, ...fieldPath) {
  if (typeof target === "function") {
    return supervisionForConstructor(target, nameOrMethod, fieldPath);
  }
  return supervisionForObject(target, nameOrMethod);
}
function supervisionForObject(object, fieldName) {
  let config;
  const ref = object[import_Internal.Internal.reference];
  if (ref) {
    if (!ref.supervisionConfig) {
      ref.supervisionConfig = new import_SupervisionConfig.GlobalConfig();
    }
    config = ref.supervisionConfig;
  } else {
    let existing = import_SupervisionConfig.bareObjectConfigs.get(object);
    if (!existing) {
      existing = new import_SupervisionConfig.GlobalConfig();
      import_SupervisionConfig.bareObjectConfigs.set(object, existing);
    }
    config = existing;
  }
  if (fieldName === void 0) {
    return config;
  }
  const child = config.child(fieldName);
  if (!child.supervision) {
    child.supervision = {};
  }
  return child.supervision;
}
function supervisionForConstructor(constructor, methodName, fieldPath) {
  const prototype = constructor.prototype;
  let map = import_SupervisionConfig.commandSupervisionConfigs.get(prototype);
  if (map === void 0) {
    map = /* @__PURE__ */ new Map();
    import_SupervisionConfig.commandSupervisionConfigs.set(prototype, map);
  }
  let config = map.get(methodName);
  if (config === void 0) {
    config = new import_SupervisionConfig.GlobalConfig();
    map.set(methodName, config);
  }
  if (fieldPath.length === 0) {
    if (!config.supervision) {
      config.supervision = {};
    }
    return config.supervision;
  }
  let current = config;
  for (const segment of fieldPath) {
    current = current.child(segment);
  }
  if (!current.supervision) {
    current.supervision = {};
  }
  return current.supervision;
}
//# sourceMappingURL=Supervision.js.map
