import type { TencentBrowserSessionData, TencentBrowserSessionSummaryData } from './tencent/session'

export type ClaimTokenStatus = 'active' | 'used' | 'expired' | 'revoked' | (string & {})

export type ClaimTaskStatus =
  | 'pending_payment'
  | 'paid'
  | 'waiting_inventory'
  | 'pending_binding_prepare'
  | 'waiting_binding'
  | 'dispatched_pending_return'
  | 'completed'
  | 'failed'
  | 'cdk_reserved'
  | 'link_generated'
  | 'claimed'
  | 'role_confirmed'
  | 'redeeming'
  | 'redeemed'
  | 'retry_pending'
  | 'manual_review'
  | 'expired'
  | 'closed'
  | (string & {})

export interface ClaimTaskInfo {
  taskId: number
  taskNo: string
  status: ClaimTaskStatus
  executorKey: string
  requiresSupportReview: boolean
  expiresAt: string | null
  claimedAt: string | null
  roleConfirmedAt: string | null
  redeemedAt: string | null
  loginType: string
  lastError: string
  browserSessionId: string
}

export interface ClaimOrderInfo {
  orderId: number
  platform: string
  platformOrderId: string
  payStatus: string
  orderStatus: string
  totalAmount: string
  totalAmountFen: number
  currency: string
}

export interface ClaimOrderItemInfo {
  orderItemId: number
  skuCode: string
  skuName: string
  quantity: number
}

export interface ClaimResultInfo {
  resultCode: string
  resultMessage: string
  screenshotReady: boolean
  screenshotUrl: string
}

export interface ClaimKuaishouCloudFlowInfo {
  flowType: 'kuaishou_cloud'
  shopId: string
  shopName: string
  guideImages: string[]
  ticket: {
    code: string
    status: string
    capturedAt: string | null
    verifiedAt: string | null
    goodsTitle: string
    leftCount: number
  }
  binding: {
    prepareStatus: string
    cloudSourceKey: string
    skuId: number
    skuName: string
    vnKey: string
    vnId: number
    bindUrl: string
    bindPreparedAt: string | null
    bindExpiresAt: string | null
    bindProbeAt: string | null
    bindProbeStatus: string
    bindProbeMessage: string
    vnPhone: string
    roleName: string
    roleId: string
  }
  role: {
    status: string
    name: string
    rid: string
    refreshedAt: string | null
    errorMessage: string
  }
  purchase: {
    autoBuyEnabled: boolean
    minAssetReserve: number
    usedKnapsack: boolean
    purchaseTriggered: boolean
    assetBefore: number
    assetAfter: number
    purchaseAt: string | null
  }
  dispatch: {
    status: string
    dispatchAt: string | null
    note: string
  }
  returnNumber: {
    status: string
    returnedAt: string | null
  }
  consume: {
    status: string
    consumedAt: string | null
    errorMessage: string
  }
}

export interface ClaimDetailData {
  tokenStatus: ClaimTokenStatus
  claimUrl: string
  flowType: 'tencent_claim' | 'kuaishou_cloud' | (string & {})
  task: ClaimTaskInfo
  order: ClaimOrderInfo
  orderItem: ClaimOrderItemInfo
  session: TencentBrowserSessionData | TencentBrowserSessionSummaryData | null
  kuaishouCloudFulfillment: ClaimKuaishouCloudFlowInfo | null
  result: ClaimResultInfo | null
}
