export type KbxSeverity = 'info' | 'warning' | 'critical'
export type KbxWorkItemStatus = 'open' | 'claimed' | 'resolved' | 'ignored'

export interface KbxWorkQueueCounter {
  key: string
  label: string
  count: number
  severity?: KbxSeverity
}

export interface KbxWorkItemAction {
  id: string
  label: string
  kind: 'navigate' | 'claim' | 'resolve' | 'retry' | 'domain'
  permission?: string
  permissionMode?: 'hide' | 'disable'
  danger?: boolean
}

export interface KbxWorkItem {
  id: string
  sourceModule: 'OMS' | 'ERP' | 'WMS' | 'COMMON'
  sourceType: string
  sourceId: string
  referenceNo: string
  sourceScreenId?: string | null
  code: string
  title: string
  detail?: string
  severity: KbxSeverity
  status: KbxWorkItemStatus
  ownerId?: string | null
  ownerName?: string | null
  occurredAt: string
  dueAt?: string | null
  ageMinutes: number
  version: number
  context?: Record<string, unknown>
  actions?: KbxWorkItemAction[]
}

export interface KbxWorkQueueResult {
  items: KbxWorkItem[]
  totalCount: number
  counters: KbxWorkQueueCounter[]
}

export type KbxReconcileStatus = 'matched' | 'mismatch' | 'pending' | 'resolved'

export interface KbxReconcileItem {
  id: string
  reconcileType: string
  referenceNo: string
  sourceLabel: string
  targetLabel: string
  expectedValue: string
  actualValue: string
  differenceValue?: string | null
  reasonCode?: string | null
  reasonText?: string | null
  status: KbxReconcileStatus
  occurredAt: string
  sourceId?: string | null
  targetId?: string | null
  version: number
}

export interface KbxReconcileSummary {
  totalCount: number
  matchedCount: number
  mismatchCount: number
  pendingCount: number
  resolvedCount: number
}

export interface KbxReconcileResult {
  items: KbxReconcileItem[]
  summary: KbxReconcileSummary
}
