"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 CommandModel_exports = {};
__export(CommandModel_exports, {
  CommandModel: () => CommandModel
});
module.exports = __toCommonJS(CommandModel_exports);
var import_elements = require("../elements/index.js");
var import_ModelTraversal = require("../logic/ModelTraversal.js");
var import_ValueModel = require("./ValueModel.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class CommandModel extends import_ValueModel.ValueModel {
  tag = import_elements.CommandElement.Tag;
  direction;
  response;
  operationalResponse;
  get fabricScoped() {
    return !!this.effectiveAccess.fabric;
  }
  get isRequest() {
    return this.effectiveDirection !== import_elements.CommandElement.Direction.Response;
  }
  get isResponse() {
    return this.effectiveDirection === import_elements.CommandElement.Direction.Response;
  }
  set isResponse(isResponse) {
    this.direction = isResponse ? import_elements.CommandElement.Direction.Response : import_elements.CommandElement.Direction.Request;
  }
  get responseModel() {
    switch (this.operationalResponse) {
      case void 0:
        return new import_ModelTraversal.ModelTraversal().findResponse(this);
      case null:
        return void 0;
      default:
        return this.operationalResponse;
    }
  }
  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 import_elements.CommandElement.Direction.Response;
      }
      return import_elements.CommandElement.Direction.Request;
    }
    return this.direction;
  }
  constructor(definition, ...children) {
    super(definition, ...children);
    this.direction = definition.direction;
    this.response = definition.response;
    this.operationalResponse = definition.operationalResponse;
  }
  toElement(omitResources = false, extra) {
    return super.toElement(omitResources, {
      direction: this.direction,
      response: this.response,
      ...extra
    });
  }
  finalize() {
    if (this.isFinal) {
      return;
    }
    const operationalResponse = this.operationalResponse ?? (this.operationalResponse = this.responseModel ?? null);
    operationalResponse?.finalize();
    super.finalize();
  }
  static Tag = import_elements.CommandElement.Tag;
  static requiresId = true;
}
CommandModel.register();
//# sourceMappingURL=CommandModel.js.map
