export type OrderListQueryInput = {
  page?: number
  pageSize?: number
  keyword?: string
  provider?: string
  executorKey?: string
  platformOrderId?: string
  payStatus?: string
  taskStatus?: string
  skuCode?: string
  dateFrom?: string
  dateTo?: string
}

export type OrderWriteInputBase = {
  provider: string
  platform: string
  shopId?: string
  shopName?: string
  platformOrderId: string
  orderStatus: string
  payStatus: string
  buyerId: string
  buyerName: string
  receiverContact: string
  totalAmount: number | string
  currency: string
  rawPayloadJson?: string | Record<string, unknown>
  paidAt?: string | null
}

export type OrderCreateInput = OrderWriteInputBase & {
  createdAt: string
  updatedAt: string
}

export type OrderUpdateInput = OrderWriteInputBase & {
  updatedAt: string
  createdAt?: string
}

export type OrderItemReplaceInput = {
  skuCode: string
  skuName: string
  quantity: number
  specJson?: string | Record<string, unknown>
  itemSnapshotJson?: string | Record<string, unknown>
  createdAt: string
  updatedAt: string
}

export type TaskListQueryInput = {
  page?: number
  pageSize?: number
  keyword?: string
  executorKey?: string
  status?: string
  platformOrderId?: string
  taskNo?: string
  skuCode?: string
  roleId?: string
  dateFrom?: string
  dateTo?: string
}

export type TaskRuntimeContextPatch = {
  runtimeSessionId?: string
  loginType?: string
  nickname?: string
  roleId?: string
  roleName?: string
  area?: string
  partitionName?: string
  screenshotPath?: string
  artifactsJson?: string | Record<string, unknown>
  stateJson?: string | Record<string, unknown>
}

export type TaskCreateInput = {
  orderId: number
  orderItemId: number
  unitIndex: number
  taskNo: string
  provider: string
  platform: string
  shopId?: string
  shopName?: string
  platformOrderId: string
  profileId: number | string
  executorKey: string
  taskStatus?: string
  deliveryStatus?: string
  resultCode?: string
  resultMessage?: string
  claimToken?: string
  claimExpiresAt?: string | null
  automationMode?: string
  requiresClaim?: boolean
  userActionStatus?: string
  attemptCount?: number
  lastError?: string
  contextJson?: string | Record<string, unknown>
  createdAt: string
  updatedAt: string
  runtimeContext?: TaskRuntimeContextPatch
}

export type TaskUpdatePatch = {
  task_status?: string
  delivery_status?: string
  result_code?: string
  result_message?: string
  claim_token?: string
  claim_expires_at?: string | null
  automation_mode?: string
  requires_claim?: boolean
  user_action_status?: string
  attempt_count?: number
  last_error?: string
  context_json?: string | Record<string, unknown>
  claimed_at?: string | null
  role_confirmed_at?: string | null
  redeemed_at?: string | null
  updated_at?: string
  runtime_session_id?: string
  login_type?: string
  nickname?: string
  role_id?: string
  role_name?: string
  area?: string
  partition_name?: string
  screenshot_path?: string
  artifacts_json?: string | Record<string, unknown>
  state_json?: string | Record<string, unknown>
}

export type KuaishouIndustryVoucherUpsertInput = {
  oid: string
  unitIndex: number
  sellerId?: string
  token?: string
  eticketType?: string
  orderId?: number | string | null
  taskId?: number | string | null
  status?: string
  validStartTime?: number
  validEndTime?: number
  consumeSerialNum?: string
  consumeDetailsJson?: string | Record<string, unknown> | unknown[]
  consumedAt?: string | null
  destroyedAt?: string | null
  sendCallbackStatus?: string
  sendCallbackAttemptCount?: number
  sendCallbackLastError?: string
  sendCallbackResponseJson?: string | Record<string, unknown>
  sendCallbackSentAt?: string | null
  rawPayloadJson?: string | Record<string, unknown>
  createdAt: string
  updatedAt: string
}

export type KuaishouIndustryVoucherUpdatePatch = Partial<
  Omit<KuaishouIndustryVoucherUpsertInput, 'oid' | 'unitIndex' | 'createdAt'>
>

export type ShortLinkCreateInput = {
  code: string
  targetUrl: string
  targetUrlHash: string
  source?: string
  taskId?: number | string | null
  expiresAt?: string | null
  createdAt: string
  updatedAt: string
}
