import type { AdminTaskListItem } from './tasks'
import type { AdminAgisoAutoDeliveryStatus } from './tasks'

export interface AdminOrderBindingSummary {
  totalTaskCount: number
  systemBoundTaskCount: number
  completedBindingTaskCount: number
  totalBindingCount: number
  reservedBindingCount: number
  consumedBindingCount: number
  releasedBindingCount: number
  systemBindingStatus: string
  userBindingStatus: string
}

export interface AdminOrderAgisoAutoDeliverySummary extends AdminAgisoAutoDeliveryStatus {
  totalTaskCount: number
  deliveredTaskCount: number
  sourceTaskId: number | null
  sourceTaskNo: string
}

export interface AdminOrderListItem {
  orderId: number
  provider: string
  platform: string
  shopId: string
  shopName: string
  platformOrderId: string
  orderStatus: string
  payStatus: string
  buyerId: string
  buyerName: string
  receiverContact: string
  totalAmount: string
  totalAmountFen: number
  currency: string
  paidAt: string | null
  createdAt: string
  updatedAt: string
  itemCount: number
  totalQuantity: number
  itemSummary: string
  taskCount: number
  systemBindingStatus: string
  userBindingStatus: string
  systemBoundTaskCount: number
  completedBindingTaskCount: number
  totalBindingCount: number
  reservedBindingCount: number
  consumedBindingCount: number
  releasedBindingCount: number
}

export interface AdminOrderDetail {
  order: {
    orderId: number
    provider: string
    platform: string
    shopId: string
    shopName: string
    platformOrderId: string
    orderStatus: string
    payStatus: string
    buyerId: string
    buyerName: string
    receiverContact: string
    totalAmount: string
    totalAmountFen: number
    currency: string
    paidAt: string | null
    createdAt: string
    updatedAt: string
    itemSummary: string
    rawPayload: Record<string, unknown>
    bindingSummary: AdminOrderBindingSummary
    agisoAutoDelivery: AdminOrderAgisoAutoDeliverySummary | null
  }
  items: Array<{
    orderItemId: number
    skuCode: string
    skuName: string
    itemTitle: string
    quantity: number
    deliveryMode: string
    spec: Record<string, unknown>
  }>
  tasks: AdminTaskListItem[]
  webhookEvents: Array<{
    eventId: number
    provider: string
    platform: string
    shopId: string
    shopName: string
    eventType: string
    eventKey: string
    signatureValid: boolean
    processed: boolean
    processError: string
    createdAt: string
  }>
}
