import { describe, expect, it } from 'vitest'
import type { KbxWorkItem } from '@kbx/contracts'

function nextActions(item: KbxWorkItem) {
  return new Set((item.actions ?? []).map(x => x.kind))
}

describe('KBX operations contract', () => {
  it('domain exception can navigate without offering unsafe manual resolution', () => {
    const item: KbxWorkItem = {
      id: '1', sourceModule: 'WMS', sourceType: 'picking-task', sourceId: 'uuid-p100', referenceNo: 'P-100', sourceScreenId: 'WMS-PICK-001', code: 'PICKING_SHORTAGE',
      title: '피킹 수량 부족', severity: 'warning', status: 'open', occurredAt: new Date().toISOString(), ageMinutes: 3, version: 1,
      actions: [{ id: 'navigate', label: '원 업무 보기', kind: 'navigate' }],
    }
    expect(nextActions(item).has('navigate')).toBe(true)
    expect(nextActions(item).has('resolve')).toBe(false)
  })

  it('retry is explicit rather than inferred from the error text', () => {
    const item: KbxWorkItem = {
      id: '2', sourceModule: 'OMS', sourceType: 'shipment', sourceId: 'uuid-s1', referenceNo: 'S-1', sourceScreenId: 'OMS-ORD-001', code: 'LABEL_FAILED',
      title: '송장 발급 실패', severity: 'warning', status: 'claimed', occurredAt: new Date().toISOString(), ageMinutes: 1, version: 2,
      actions: [{ id: 'retry', label: '재처리', kind: 'retry' }],
    }
    expect(nextActions(item)).toEqual(new Set(['retry']))
  })
})
