export type KbxBarcodeSource = 'keyboard-wedge' | 'camera' | 'manual'

export interface KbxBarcodeEvent {
  rawValue: string
  normalizedValue: string
  source: KbxBarcodeSource
  occurredAt: number
}

export type KbxWmsPickingStage =
  | 'ready'
  | 'await-location'
  | 'await-item'
  | 'processing'
  | 'completed'
  | 'blocked'

export interface KbxWmsCurrentLine {
  lineId: string
  lineNo: number
  locationCode: string
  itemId: string
  itemCode: string
  itemName: string
  itemOption?: string | null
  barcode: string
  requiredQty: number
  pickedQty: number
  remainingQty: number
}

export interface KbxWmsPickingTask {
  taskId: string
  taskNo: string
  stage: KbxWmsPickingStage
  status: string
  completedLines: number
  totalLines: number
  completedQty: number
  totalQty: number
  version: number
  currentLine?: KbxWmsCurrentLine | null
  message?: string | null
}

export interface KbxWmsScanCommand {
  taskId: string
  barcode: string
  source: KbxBarcodeSource
  idempotencyKey: string
  expectedVersion: number
  occurredAt: string
}

export interface KbxWmsScanResult {
  accepted: boolean
  duplicate: boolean
  task: KbxWmsPickingTask
  feedback: 'success' | 'warning' | 'error' | 'neutral'
  message: string
}

export type KbxWmsExceptionType =
  | 'no-stock'
  | 'short-quantity'
  | 'wrong-location'
  | 'damaged-item'
  | 'barcode-issue'
  | 'other'

export interface KbxWmsExceptionCommand {
  taskId: string
  lineId?: string | null
  type: KbxWmsExceptionType
  memo?: string | null
  idempotencyKey: string
  expectedVersion: number
}

export interface KbxWmsNetworkState {
  online: boolean
  pendingCommands: number
  syncing: boolean
}

export interface KbxWmsSetQuantityCommand {
  taskId: string
  lineId: string
  pickedQty: number
  idempotencyKey: string
  expectedVersion: number
}
