export { ORDER_STATUSES } from '../../../shared/constants/order-status.js'

/**
 * Переходы, которые делает админ через PATCH /api/admin/orders/:id/status
 * (подтверждение получения пользователем — отдельный эндпоинт).
 */
export function canTransitionAdminOrderStatus(order, next) {
  const from = order.status
  const dt = order.deliveryType
  if (from === next) return true

  switch (from) {
    case 'DRAFT':
      return next === 'PENDING_PAYMENT' || next === 'CANCELLED'
    case 'DELIVERY_FEE_ADJUSTMENT':
      return next === 'CANCELLED'
    case 'PENDING_PAYMENT':
      return next === 'CANCELLED'
    case 'PAYMENT_VERIFICATION':
      return next === 'PAID' || next === 'CANCELLED'
    case 'PAID':
      return next === 'IN_PROGRESS' || next === 'CANCELLED'
    case 'IN_PROGRESS':
      if (next === 'CANCELLED') return true
      if (dt === 'delivery') return next === 'SHIPPED'
      if (dt === 'pickup') return next === 'READY_FOR_PICKUP'
      return false
    case 'SHIPPED':
    case 'READY_FOR_PICKUP':
    case 'DONE':
    case 'CANCELLED':
      return false
    default:
      return false
  }
}

/** @deprecated используйте canTransitionAdminOrderStatus */
export function canTransitionOrderStatus(from, to) {
  return canTransitionAdminOrderStatus({ status: from, deliveryType: 'delivery' }, to)
}
