import { describe, expect, it } from 'vitest'
import { canTransitionAdminOrderStatus } from '../order-status.js'

describe('canTransitionAdminOrderStatus', () => {
  const delivery = { deliveryType: 'delivery' }
  const pickup = { deliveryType: 'pickup' }

  it('DRAFT → PENDING_PAYMENT', () => {
    expect(canTransitionAdminOrderStatus({ status: 'DRAFT', ...delivery }, 'PENDING_PAYMENT')).toBe(true)
  })

  it('DRAFT → CANCELLED', () => {
    expect(canTransitionAdminOrderStatus({ status: 'DRAFT', ...delivery }, 'CANCELLED')).toBe(true)
  })

  it('DRAFT cannot skip to PAID', () => {
    expect(canTransitionAdminOrderStatus({ status: 'DRAFT', ...delivery }, 'PAID')).toBe(false)
  })

  it('PAID → IN_PROGRESS', () => {
    expect(canTransitionAdminOrderStatus({ status: 'PAID', ...delivery }, 'IN_PROGRESS')).toBe(true)
  })

  it('IN_PROGRESS (delivery) → SHIPPED', () => {
    expect(canTransitionAdminOrderStatus({ status: 'IN_PROGRESS', ...delivery }, 'SHIPPED')).toBe(true)
  })

  it('IN_PROGRESS (pickup) → READY_FOR_PICKUP', () => {
    expect(canTransitionAdminOrderStatus({ status: 'IN_PROGRESS', ...pickup }, 'READY_FOR_PICKUP')).toBe(true)
  })

  it('IN_PROGRESS (delivery) cannot go to READY_FOR_PICKUP', () => {
    expect(canTransitionAdminOrderStatus({ status: 'IN_PROGRESS', ...delivery }, 'READY_FOR_PICKUP')).toBe(false)
  })

  it('DONE allows no transitions', () => {
    expect(canTransitionAdminOrderStatus({ status: 'DONE', ...delivery }, 'CANCELLED')).toBe(false)
    expect(canTransitionAdminOrderStatus({ status: 'DONE', ...delivery }, 'PAID')).toBe(false)
  })

  it('same status returns true', () => {
    expect(canTransitionAdminOrderStatus({ status: 'DRAFT', ...delivery }, 'DRAFT')).toBe(true)
  })
})
