/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { CommandElement } from "../elements/index.js";
import { ModelTraversal } from "../logic/ModelTraversal.js";
import { ValueModel } from "./ValueModel.js";
class CommandModel extends ValueModel {
  tag = CommandElement.Tag;
  direction;
  response;
  get fabricScoped() {
    return !!this.effectiveAccess.fabric;
  }
  get isRequest() {
    return this.effectiveDirection === CommandElement.Direction.Request;
  }
  get isResponse() {
    return this.effectiveDirection === CommandElement.Direction.Response;
  }
  get responseModel() {
    return new ModelTraversal().findResponse(this);
  }
  get effectiveDirection() {
    return this.direction ?? this.base?.direction;
  }
  get requiredFields() {
    return { ...super.requiredFields, id: this.id };
  }
  /**
   * Commands may re-use the ID for request and response so identification requires the ID in conjunction with the
   * direction.
   */
  get discriminator() {
    if (this.direction === void 0) {
      if (this.name.endsWith("Response")) {
        return CommandElement.Direction.Response;
      }
      return CommandElement.Direction.Request;
    }
    return this.direction;
  }
  constructor(definition, ...children) {
    super(definition, ...children);
    this.direction = definition.direction;
    this.response = definition.response;
  }
  toElement(omitResources = false, extra) {
    return super.toElement(omitResources, {
      direction: this.direction,
      response: this.response,
      ...extra
    });
  }
  static Tag = CommandElement.Tag;
  static requiresId = true;
}
CommandModel.register();
export {
  CommandModel
};
//# sourceMappingURL=CommandModel.js.map
