export type OrderRow = {
  id: number
  provider: string
  platform: string
  shop_id: string
  shop_name: string
  platform_order_id: string
  order_status: string
  pay_status: string
  buyer_id: string
  buyer_name: string
  receiver_contact: string
  total_amount: number | string
  currency: string
  raw_payload_json: string | Record<string, unknown>
  paid_at: string | null
  created_at: string
  updated_at: string
}

export type OrderListRow = OrderRow & {
  task_count?: number
}

export type OrderItemRow = {
  id: number
  order_id: number
  sku_code: string
  sku_name: string
  quantity: number
  spec_json: string | Record<string, unknown>
  item_snapshot_json?: string | Record<string, unknown>
  created_at?: string
  updated_at?: string
}

export type TaskRow = {
  id: number
  order_id: number
  order_item_id: number
  unit_index: number
  platform_order_id: string
  profile_id: number
  task_no: string
  executor_key: string
  task_status: string
  delivery_status: string
  result_code: string
  result_message: string
  automation_mode: string
  requires_claim: boolean
  user_action_status: string
  attempt_count: number
  runtime_session_id: string
  login_type: string
  nickname: string
  role_name: string
  role_id: string
  area: string
  partition_name: string
  claim_token: string
  claim_expires_at?: string | null
  primary_claim_token: string
  primary_claim_token_id: number | null
  primary_claim_token_status: string
  primary_claim_expires_at?: string | null
  artifacts_json: string | Record<string, unknown>
  context_json: string | Record<string, unknown>
  screenshot_path: string
  last_error: string
  retry_count: number
  created_at: string
  updated_at: string
  kuaishou_ticket_status?: string
  kuaishou_ticket_code_masked?: string
  kuaishou_bind_url?: string
  kuaishou_vn_phone?: string
  kuaishou_role_name?: string
  kuaishou_role_id?: string
  kuaishou_dispatch_status?: string
  kuaishou_consume_status?: string
  kuaishou_source_key?: string
  kuaishou_state_updated_at?: string | null
  claimed_at: string | null
  role_confirmed_at: string | null
  redeemed_at: string | null
  sku_code?: string
  sku_name?: string
}

export type ClaimTokenRow = {
  id: number
  token: string
  status: string
  expired_at: string | null
  created_at?: string
  updated_at?: string
}

export type TaskEventRow = {
  id: number
  event_type: string
  payload_json: string | Record<string, unknown>
  created_at: string
}

export type KuaishouIndustryVoucherRow = {
  id: number
  voucher_code: string
  oid: string
  order_id: number | null
  task_id: number | null
  unit_index: number
  seller_id: string
  token: string
  eticket_type: string
  status: string
  valid_start_time: number | string
  valid_end_time: number | string
  consume_serial_num: string
  consume_details_json: string | Record<string, unknown> | unknown[]
  consumed_at: string | null
  destroyed_at: string | null
  send_callback_status: string
  send_callback_attempt_count: number
  send_callback_last_error: string
  send_callback_response_json: string | Record<string, unknown>
  send_callback_sent_at: string | null
  raw_payload_json: string | Record<string, unknown>
  created_at: string
  updated_at: string
}

export type ShortLinkRow = {
  id: number
  code: string
  target_url: string
  target_url_hash: string
  source: string
  task_id: number | null
  expires_at: string | null
  visit_count: number
  last_visited_at: string | null
  created_at: string
  updated_at: string
}

export type OrderListQueryResult = {
  items: OrderListRow[]
  total: number
}

export type TaskListQueryResult = {
  items: TaskRow[]
  total: number
}
