"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 BehaviorResource_exports = {};
__export(BehaviorResource_exports, {
  BehaviorResource: () => BehaviorResource
});
module.exports = __toCommonJS(BehaviorResource_exports);
var import_general = require("@matter/general");
var import_model = require("@matter/model");
var import_types = require("@matter/types");
var import_CommandResource = require("./CommandResource.js");
var import_PropertyResource = require("./PropertyResource.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class BehaviorResource extends import_PropertyResource.PropertyResource {
  #behavior;
  get valueKind() {
    return "cluster";
  }
  constructor(behavior, parent) {
    const { id, supervisor } = behavior.type;
    if (supervisor === void 0) {
      throw new import_general.InternalError(`API behavior reference has no value supervisor`);
    }
    super(parent, id, supervisor, behavior.endpoint.path.at(id));
    this.#behavior = behavior;
  }
  get value() {
    return this.#behavior.state;
  }
  write() {
    throw new import_types.StatusResponse.UnsupportedWriteError(`Only patch supported for this path`);
  }
  async childFor(id) {
    if (id === "state") {
      return new import_PropertyResource.PropertyResource(this, "state", this.supervisor, this.dataModelPath.at("state"));
    }
    if (this.schema instanceof import_model.ClusterModel) {
      const command = this.schema.conformant.commands.for(id, import_model.CommandModel);
      if (command) {
        return new import_CommandResource.CommandResource(this, this.#behavior, command);
      }
    }
    return super.childFor(id);
  }
  get rootSupervisor() {
    return this.supervisor;
  }
}
//# sourceMappingURL=BehaviorResource.js.map
