"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 StatusResponseError_exports = {};
__export(StatusResponseError_exports, {
  ReceivedStatusResponseError: () => ReceivedStatusResponseError,
  StatusResponse: () => StatusResponse,
  StatusResponseError: () => StatusResponseError,
  UnknownStatusResponseError: () => UnknownStatusResponseError
});
module.exports = __toCommonJS(StatusResponseError_exports);
var import_Status = require("#globals/Status.js");
var import_general = require("@matter/general");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const specializationIndex = {};
class StatusResponseError extends import_general.MatterError {
  constructor(message, code, clusterCode) {
    super(message);
    this.code = code;
    this.clusterCode = clusterCode;
  }
  get bareMessage() {
    return this.message.replace(/ \(code .+\)$/, "");
  }
  static is(error, ...codes) {
    return error instanceof StatusResponseError && (!codes.length || codes.includes(error.code));
  }
  get id() {
    const id = super.id;
    if (id === "status-response") {
      const code = import_Status.Status[this.code];
      if (code) {
        return (0, import_general.decamelize)(code);
      }
    }
    return id;
  }
  static create(code, message, clusterCode) {
    const type = specializationIndex[code];
    if (type) {
      return new type(message, clusterCode);
    }
    throw new UnknownStatusResponseError(message ?? "Unknown status response", code, clusterCode);
  }
}
class UnknownStatusResponseError extends StatusResponseError {
}
const StatusResponse = Object.fromEntries(
  Object.entries(import_Status.Status).map(([name, code]) => {
    if (typeof code !== "number") {
      return void 0;
    }
    const ct = {
      [name]: class extends StatusResponseError {
        constructor(message, clusterCode) {
          if (message === void 0) {
            message = (0, import_general.capitalize)((0, import_general.decamelize)(name, " "));
          }
          super(message, code, clusterCode);
          let codeStr = `code ${code}`;
          if (clusterCode !== void 0) {
            codeStr = `${codeStr}; cluster code ${clusterCode}`;
          }
          this.message = `${message} (${codeStr})`;
        }
      }
    };
    const constructor = ct[name];
    Object.defineProperty(constructor, "name", { value: name });
    specializationIndex[code] = constructor;
    return [`${name}Error`, constructor];
  }).filter((e) => e)
);
class ReceivedStatusResponseError extends StatusResponseError {
}
//# sourceMappingURL=StatusResponseError.js.map
