var _a, _b;
const SHIPMENT_CANCEL_NOT_ALLOWED_MARKER = /* @__PURE__ */ Symbol.for("@open-mercato/shipping_carriers/ShipmentCancelNotAllowedError");
class ShipmentCancelNotAllowedError extends (_b = Error, _a = SHIPMENT_CANCEL_NOT_ALLOWED_MARKER, _b) {
  constructor(status) {
    super(`Shipment cannot be cancelled in its current status: ${status}`);
    this[_a] = true;
    this.name = "ShipmentCancelNotAllowedError";
  }
}
function isShipmentCancelNotAllowedError(error) {
  return !!error && typeof error === "object" && error[SHIPMENT_CANCEL_NOT_ALLOWED_MARKER] === true;
}
const VALID_SHIPPING_TRANSITIONS = {
  label_created: ["picked_up", "in_transit", "cancelled"],
  picked_up: ["in_transit", "cancelled"],
  in_transit: ["out_for_delivery", "delivered", "returned", "failed_delivery"],
  out_for_delivery: ["delivered", "returned", "failed_delivery"],
  failed_delivery: ["in_transit", "out_for_delivery", "delivered", "returned", "cancelled"]
};
const TERMINAL_SHIPPING_STATUSES = /* @__PURE__ */ new Set([
  "delivered",
  "returned",
  "cancelled"
]);
function isValidShippingTransition(from, to) {
  if (from === to) return false;
  const allowed = VALID_SHIPPING_TRANSITIONS[from];
  if (!allowed) return false;
  return allowed.includes(to);
}
function syncShipmentStatus(shipment, newStatus) {
  const currentStatus = shipment.unifiedStatus;
  if (!isValidShippingTransition(currentStatus, newStatus)) return false;
  shipment.unifiedStatus = newStatus;
  return true;
}
function getTerminalShippingEvent(status) {
  if (status === "delivered") return "shipping_carriers.shipment.delivered";
  if (status === "returned") return "shipping_carriers.shipment.returned";
  if (status === "cancelled") return "shipping_carriers.shipment.cancelled";
  return null;
}
export {
  ShipmentCancelNotAllowedError,
  TERMINAL_SHIPPING_STATUSES,
  getTerminalShippingEvent,
  isShipmentCancelNotAllowedError,
  isValidShippingTransition,
  syncShipmentStatus
};
//# sourceMappingURL=status-sync.js.map
