export const ORDER_STATUSES = Object.freeze([
  "DRAFT",
  "PENDING_PAYMENT",
  "PAID",
  "IN_PROGRESS",
  "SHIPPED",
  "READY_FOR_PICKUP",
  "DONE",
  "CANCELLED",
]);

/**
 * Допустимые переходы статусов, доступные админу.
 * Значение — массив из next-статусов.
 * Для IN_PROGRESS: объект с ключами по deliveryType.
 */
export const ADMIN_ORDER_TRANSITIONS = Object.freeze({
  DRAFT: ["PENDING_PAYMENT", "CANCELLED"],
  PENDING_PAYMENT: ["PAID", "CANCELLED"],
  PAID: ["IN_PROGRESS", "CANCELLED"],
  IN_PROGRESS: Object.freeze({
    delivery: ["SHIPPED", "CANCELLED"],
    pickup: ["READY_FOR_PICKUP", "CANCELLED"],
  }),
});

export function getNextAdminStatuses(from, deliveryType) {
  const transition = ADMIN_ORDER_TRANSITIONS[from];
  if (!transition) return [];
  if (Array.isArray(transition)) return [...transition];
  return transition[deliveryType] ? [...transition[deliveryType]] : [];
}

export function canTransitionAdminOrderStatus(order, next) {
  const from = order.status;
  if (from === next) return true;
  return getNextAdminStatuses(from, order.deliveryType).includes(next);
}
