/** 列表行状态：兼容大小写/空值，并在缺省时根据时间戳推断 */
export function inferReportStatus(row: Record<string, any>): string {
  const raw = (row.status ?? row.Status ?? '').toString().trim().toLowerCase()
  if (raw) return raw
  if (row.error_message) return 'failed'
  if (row.finished_at) return 'success'
  if (row.started_at) return 'running'
  return 'pending'
}

export function normalizeReportRows<T extends Record<string, any>>(rows: T[]): (T & { status: string })[] {
  return rows.map((row) => ({
    ...row,
    status: inferReportStatus(row),
  }))
}

export const reportStatusLabel: Record<string, string> = {
  pending: '等待中',
  running: '生成中',
  success: '成功',
  failed: '失败',
}

export function reportStatusColor(status: string): string {
  switch (status) {
    case 'success':
      return 'green'
    case 'failed':
      return 'red'
    case 'running':
      return 'blue'
    case 'pending':
      return 'gray'
    default:
      return 'gray'
  }
}
