export type OrderListQueryInput = {
  page?: number
  pageSize?: number
  platformOrderId?: string
  payStatus?: 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
  status?: string
  platformOrderId?: string
  taskNo?: string
  skuCode?: string
  roleId?: string
  dateFrom?: string
  dateTo?: string
}

export type TaskTencentContextPatch = {
  browserSessionId?: 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
  inventoryStatus?: 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
  tencentContext?: TaskTencentContextPatch
}

export type TaskUpdatePatch = {
  task_status?: string
  inventory_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
  browser_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 InventoryListQueryInput = {
  page?: number
  pageSize?: number
  skuCode?: string
  credentialType?: string
  status?: string
  batchNo?: string
  inventoryGroupCode?: string
  allowedInventoryGroupCodes?: string[] | null
}

export type InventorySkuSuggestionQueryInput = {
  credentialType?: string
  keyword?: string
  limit?: number
  inventoryGroupCode?: string
  allowedInventoryGroupCodes?: string[] | null
}

export type InventoryCreateItemInput = {
  batchNo?: string
  skuCode: string
  credentialType?: string
  inventoryGroupCode?: string
  displayValue: string
  payload?: Record<string, unknown>
  createdAt: string
  updatedAt: string
}

export type WebhookEventListQueryInput = {
  page?: number
  pageSize?: number
  provider?: string
  platform?: string
  platformOrderId?: string
  processed?: string
  visibility?: string
  relatedOrderId?: string
  dateFrom?: string
  dateTo?: string
}

export type WebhookEventCreateInput = {
  provider: string
  platform: string
  shopId?: string
  shopName?: string
  eventType: string
  eventKey: string
  signatureValid?: boolean
  headersJson?: string | Record<string, unknown>
  queryJson?: string | Record<string, unknown>
  bodyJson?: string | Record<string, unknown>
  processed?: boolean
  processError?: string
  relatedOrderId?: number | null
  createdAt: string
}

export type WebhookEventUpdatePatch = {
  processed?: boolean
  process_error?: string
  related_order_id?: number | null
}
