"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 ClientCommandMethod_exports = {};
__export(ClientCommandMethod_exports, {
  ClientCommandMethod: () => ClientCommandMethod
});
module.exports = __toCommonJS(ClientCommandMethod_exports);
var import_Node = require("#node/Node.js");
var import_protocol = require("@matter/protocol");
var import_types = require("@matter/types");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function ClientCommandMethod(name, commandModel) {
  const largeMessage = !!commandModel?.effectiveQuality.largeMessage;
  const temp = {
    // The actual implementation
    async [name](fields, context) {
      const node = this.env.get(import_Node.Node);
      const invoke = (0, import_protocol.Invoke)({
        commands: [
          import_protocol.Invoke.ConcreteCommandRequest({
            endpoint: this.endpoint,
            cluster: this.cluster,
            command: name,
            fields
          })
        ]
      });
      if (largeMessage) {
        invoke.largeMessage = true;
      }
      const chunks = node.interaction.invoke(invoke, context);
      for await (const chunk of chunks) {
        for (const entry of chunk) {
          switch (entry.kind) {
            case "cmd-status":
              if (entry.status !== import_types.Status.Success) {
                throw import_types.StatusResponseError.create(entry.status, void 0, entry.clusterStatus);
              }
              return;
            case "cmd-response":
              return entry.data;
          }
        }
      }
    }
  };
  return temp[name];
}
//# sourceMappingURL=ClientCommandMethod.js.map
