/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { InternalError } from "@matter/general";
import { ClusterModel, CommandModel } from "@matter/model";
import { StatusResponse } from "@matter/types";
import { CommandResource } from "./CommandResource.js";
import { PropertyResource } from "./PropertyResource.js";
class BehaviorResource extends PropertyResource {
  #behavior;
  get valueKind() {
    return "cluster";
  }
  constructor(behavior, parent) {
    const { id, supervisor } = behavior.type;
    if (supervisor === void 0) {
      throw new 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 StatusResponse.UnsupportedWriteError(`Only patch supported for this path`);
  }
  async childFor(id) {
    if (id === "state") {
      return new PropertyResource(this, "state", this.supervisor, this.dataModelPath.at("state"));
    }
    if (this.schema instanceof ClusterModel) {
      const command = this.schema.conformant.commands.for(id, CommandModel);
      if (command) {
        return new CommandResource(this, this.#behavior, command);
      }
    }
    return super.childFor(id);
  }
  get rootSupervisor() {
    return this.supervisor;
  }
}
export {
  BehaviorResource
};
//# sourceMappingURL=BehaviorResource.js.map
