/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Internal } from "../state/managed/Internal.js";
import { bareObjectConfigs, commandSupervisionConfigs, GlobalConfig } from "./SupervisionConfig.js";
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[Internal.reference];
  if (ref) {
    if (!ref.supervisionConfig) {
      ref.supervisionConfig = new GlobalConfig();
    }
    config = ref.supervisionConfig;
  } else {
    let existing = bareObjectConfigs.get(object);
    if (!existing) {
      existing = new GlobalConfig();
      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 = commandSupervisionConfigs.get(prototype);
  if (map === void 0) {
    map = /* @__PURE__ */ new Map();
    commandSupervisionConfigs.set(prototype, map);
  }
  let config = map.get(methodName);
  if (config === void 0) {
    config = new 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;
}
export {
  Supervision
};
//# sourceMappingURL=Supervision.js.map
