import { ORDER_STATUSES as SHARED_ORDER_STATUSES } from '@shared/constants/order-status'

export const ORDER_STATUSES = SHARED_ORDER_STATUSES as typeof SHARED_ORDER_STATUSES

export type OrderStatus = (typeof ORDER_STATUSES)[number]

export function getAdminNextOrderStatuses(status: string, deliveryType: 'delivery' | 'pickup'): OrderStatus[] {
  switch (status) {
    case 'DRAFT':
      return ['PENDING_PAYMENT', 'CANCELLED']
    case 'DELIVERY_FEE_ADJUSTMENT':
      return ['CANCELLED']
    case 'PENDING_PAYMENT':
      return ['CANCELLED']
    case 'PAYMENT_VERIFICATION':
      return ['PAID', 'CANCELLED']
    case 'PAID':
      return ['IN_PROGRESS', 'CANCELLED']
    case 'IN_PROGRESS':
      if (deliveryType === 'delivery') return ['SHIPPED', 'CANCELLED']
      return ['READY_FOR_PICKUP', 'CANCELLED']
    default:
      return []
  }
}

export function canTransitionOrderStatus(from: string, to: string): boolean {
  if (from === to) return true
  return getAdminNextOrderStatuses(from, 'delivery').includes(to as OrderStatus)
}
