const VALID_TRANSITIONS = {
  pending: ["authorized", "captured", "failed", "expired", "cancelled"],
  authorized: ["captured", "partially_captured", "cancelled", "failed"],
  captured: ["refunded", "partially_refunded"],
  partially_captured: ["captured", "refunded", "partially_refunded", "cancelled"],
  partially_refunded: ["refunded"]
  // Terminal states: refunded, cancelled, failed, expired — no valid transitions out
};
const TERMINAL_STATUSES = /* @__PURE__ */ new Set([
  "refunded",
  "cancelled",
  "failed",
  "expired"
]);
function isValidTransition(from, to) {
  if (from === to) return false;
  const allowed = VALID_TRANSITIONS[from];
  if (!allowed) return false;
  return allowed.includes(to);
}
function isTerminalStatus(status) {
  return TERMINAL_STATUSES.has(status);
}
const MANUAL_ACTION_TARGET_STATUSES = {
  capture: ["captured", "partially_captured"],
  refund: ["refunded", "partially_refunded"],
  cancel: ["cancelled"]
};
function canApplyManualAction(action, from) {
  if (isTerminalStatus(from)) return false;
  const targets = MANUAL_ACTION_TARGET_STATUSES[action];
  if (!targets) return false;
  if (targets.includes(from)) return true;
  return targets.some((target) => isValidTransition(from, target));
}
export {
  TERMINAL_STATUSES,
  canApplyManualAction,
  isTerminalStatus,
  isValidTransition
};
//# sourceMappingURL=status-machine.js.map
