/**
 * @license
 * Copyright 2025-2026 Open Home Foundation
 * SPDX-License-Identifier: Apache-2.0
 */
const MatterStatusNames = {
  0: "Success",
  1: "Failure",
  125: "InvalidSubscription",
  126: "UnsupportedAccess",
  127: "UnsupportedEndpoint",
  128: "InvalidAction",
  129: "UnsupportedCommand",
  133: "InvalidCommand",
  134: "UnsupportedAttribute",
  135: "ConstraintError",
  136: "UnsupportedWrite",
  137: "ResourceExhausted",
  139: "NotFound",
  140: "UnreportableAttribute",
  141: "InvalidDataType",
  143: "UnsupportedRead",
  146: "DataVersionMismatch",
  148: "Timeout",
  155: "UnsupportedNode",
  156: "Busy",
  157: "AccessRestricted",
  195: "UnsupportedCluster",
  197: "NoUpstreamSubscription",
  198: "NeedsTimedInteraction",
  199: "UnsupportedEvent",
  200: "PathsExhausted",
  201: "TimedRequestMismatch",
  202: "FailsafeRequired",
  203: "InvalidInState",
  204: "NoCommandResponse",
  205: "TermsAndConditionsChanged",
  206: "MaintenanceRequired",
  207: "DynamicConstraintError",
  208: "AlreadyExists",
  209: "InvalidTransportType"
};
function getMatterStatusName(status) {
  return MatterStatusNames[status] ?? `Unknown(${status})`;
}
function successResult() {
  return { success: true, status: 0, statusName: "Success" };
}
function failureResult(status) {
  return { success: false, status, statusName: getMatterStatusName(status) };
}
function resultFromStatus(status) {
  const statusName = getMatterStatusName(status);
  return { success: status === 0, status, statusName };
}
function analyzeBatchResults(results) {
  if (!results || results.length === 0) {
    return {
      outcome: "all_failed",
      successCount: 0,
      failureCount: 0,
      errorCounts: {},
      message: "No response/results returned"
    };
  }
  let successCount = 0;
  let failureCount = 0;
  const errorCounts = {};
  for (const result of results) {
    if (result.status === 0) {
      successCount++;
    } else {
      failureCount++;
      errorCounts[result.status] = (errorCounts[result.status] ?? 0) + 1;
    }
  }
  let outcome;
  if (failureCount === 0) {
    outcome = "all_success";
  } else if (successCount === 0) {
    outcome = "all_failed";
  } else {
    outcome = "partial";
  }
  const message = formatBatchMessage(outcome, successCount, failureCount, errorCounts);
  return { outcome, successCount, failureCount, errorCounts, message };
}
function formatBatchMessage(outcome, successCount, failureCount, errorCounts) {
  const entryWord = (count) => count === 1 ? "entry" : "entries";
  if (outcome === "all_success") {
    return "Write successful";
  }
  const errorParts = Object.entries(errorCounts).map(([code, count]) => {
    const statusCode = parseInt(code, 10);
    return `${count}x ${getMatterStatusName(statusCode)} (${code})`;
  }).join(", ");
  if (outcome === "all_failed") {
    return `All ${failureCount} ${entryWord(failureCount)} failed: ${errorParts}`;
  }
  return `Partial failure: ${successCount} ${entryWord(successCount)} succeeded, ${failureCount} failed (${errorParts}). Please verify.`;
}
export {
  MatterStatusNames,
  analyzeBatchResults,
  failureResult,
  getMatterStatusName,
  resultFromStatus,
  successResult
};
//# sourceMappingURL=matter-status.js.map
