export interface AdminTaskBindingSummary {
  totalBindingCount: number
  reservedBindingCount: number
  consumedBindingCount: number
  releasedBindingCount: number
  roleKeys: string[]
}

export interface AdminAgisoAutoDeliveryStatus {
  status: string
  trigger: string
  reason: string
  platformOrderId: string
  responseStatus: number
  errorMessage: string
  requestId: string
  updatedAt: string | null
}

export interface AdminTaskListItem {
  taskId: number
  taskNo: string
  platformOrderId: string
  skuCode: string
  skuName: string
  status: string
  executorKey: string
  deliveryStatus: string
  resultCode: string
  resultMessage: string
  systemBindingStatus: string
  userBindingStatus: string
  loginType: string
  roleName: string
  roleId: string
  browserSessionId: string
  claimedAt: string | null
  roleConfirmedAt: string | null
  redeemedAt: string | null
  retryCount: number
  bindingSummary: AdminTaskBindingSummary
  lastError: string
  createdAt: string
  updatedAt: string
  inventoryDisplayMasked: string
  inventoryCredentialType: string
  claimToken: string
  screenshotPath: string
  agisoAutoDelivery: AdminAgisoAutoDeliveryStatus | null
}

export interface AdminTaskOperations {
  canRetry: boolean
  canReleaseInventory: boolean
  canRegenerateClaimLink: boolean
  canClose: boolean
  canMarkManualReview: boolean
  canCompleteManualDispatch: boolean
  canPrepareKuaishouCloudFulfillment: boolean
  canRefreshKuaishouCloudRoleInfo: boolean
  canDispatchKuaishouCloudFulfillment: boolean
  canReturnKuaishouCloudFulfillment: boolean
  canSupportConfirmRole: boolean
  canSupportRedeem: boolean
  canViewSensitiveTaskData: boolean
}

export interface AdminTaskActionResponse {
  task: {
    taskId: number
    taskNo: string
    status: string
    deliveryStatus: string
    resultCode: string
    resultMessage: string
    inventoryItemId: number | null
    primaryClaimTokenId: number | null
    lastError: string
    updatedAt: string
  }
  claimUrl?: string
  token?: string
}

export interface AdminTaskDetail {
  task: AdminTaskListItem
  order: null | {
    orderId: number
    provider: string
    platform: string
    shopId: string
    shopName: string
    platformOrderId: string
    payStatus: string
    orderStatus: string
  }
  orderItem: null | {
    orderItemId: number
    skuCode: string
    skuName: string
    quantity: number
  }
  claimToken: null | {
    primaryClaimTokenId: number
    token: string
    status: string
    expiredAt: string
    claimUrl: string
  }
  inventory: null | {
    inventoryItemId: number
    skuCode: string
    batchNo: string
    credentialType: string
    displayValue: string
    status: string
  }
  inventoryBindings: Array<{
    bindingId: number
    inventoryItemId: number
    roleKey: string
    quantity: number
    bindingStatus: string
    inventoryStatus: string
    skuCode: string
    batchNo: string
    credentialType: string
    displayValue: string
    invalidReason: string
    consumedAt: string | null
    releasedAt: string | null
    createdAt: string
    updatedAt: string
    metadata: Record<string, unknown>
    isPrimary: boolean
    canRelease: boolean
  }>
  artifacts: Record<string, unknown>
  screenshotUrl: string
  review: {
    required: boolean
    screenshotCapturedAt: string | null
    roleId: string
    roleName: string
  }
  redeemResolution: null | {
    status: string
    taskStatus: string
    replacementCount: number
    finishedAt: string | null
    attempts: Array<{
      attempt: number
      inventoryItemId: number | null
      codeMasked: string
      credentialType: string
      outcome: string
      resultCode: string
      resultMessage: string
    }>
  }
  kuaishouCloudFulfillment: null | {
    flowType: string
    configId: string
    internalSkuCode: string
    internalSkuName: string
    ticket: {
      code: string
      capturedAt: string | null
      status: string
      verifiedAt: string | null
      goodsTitle: string
      leftCount: number
    }
    binding: {
      prepareStatus: string
      cloudSourceKey: string
      skuId: number
      skuName: string
      vnKey: string
      vnId: number
      vnPhone: string
      bindUrl: string
      bindPreparedAt: string | null
      bindExpiresAt: string | null
      bindProbeAt: string | null
      bindProbeStatus: string
      bindProbeMessage: string
    }
    role: {
      status: string
      name: string
      rid: string
      refreshedAt: string | null
      errorMessage: string
      rawInfo: Record<string, unknown> | null
    }
    purchase: {
      autoBuyEnabled: boolean
      minAssetReserve: number
      usedKnapsack: boolean
      purchaseTriggered: boolean
      assetBefore: number
      assetAfter: number
      purchaseAt: string | null
    }
    dispatch: {
      status: string
      dispatchAt: string | null
      sendType: number
      note: string
    }
    returnNumber: {
      status: string
      returnedAt: string | null
      autoReturnEnabled: boolean
    }
    consume: {
      status: string
      shopId: string
      shopName: string
      autoConsumeEnabled: boolean
      consumedAt: string | null
      errorMessage: string
    }
    notes: string
  }
  manualDispatch: null | {
    outcome: string
    deliveryReference: string
    deliveredCredential: string
    resultMessage: string
    completedAt: string | null
    completedBy: null | {
      userId: number
      username: string
      role: string
    }
  }
  events: Array<{
    eventId: number
    eventType: string
    payload: Record<string, unknown>
    createdAt: string
  }>
  operations: AdminTaskOperations
}
