import { apiDelete, apiGet, apiPost, apiPut } from '@/lib/http'
import type {
  UploadedFile,
  AdminWorkerDetail,
  AdminWorkerWithdrawalAccount,
  WorkCategory,
  WorkOrder,
  WorkOrderEvent,
  WorkOrderShare,
  WorkOrderStatistics,
  WorkProductRule,
  WorkProductRuleMapping,
  KuaishouMatchSource,
  WorkProductMatchLog,
  WorkerDepositUnfreeze,
  WorkerFinanceConfig,
  WorkerHallConfig,
  WorkerFinanceRequest,
  WorkerCancelRequest,
  WorkerOrderFeedback,
  WorkerAfterSalesCase,
  WorkerAfterSalesCaseEvent,
  WorkerPlatformNotificationConfig,
  WorkerProductMatchConfig,
  WorkerAnnouncementConfig,
  WorkerLevel,
  WorkerListResponse,
  WorkerUser,
  WorkerWalletLedger,
} from '@/types/worker-platform'

type WorkOrderVoucherConsumeResult = {
  ok: boolean
  voucherCount: number
  consumedCount: number
  alreadyConsumedCount: number
  failedCount: number
  voucherCodes: string[]
  errorMessage: string
}

export type AdminLeaderboardPeriod = 'all' | 'daily' | 'weekly' | 'monthly'

export type AdminWorkerLeaderboardEntry = {
  rank: number
  workerId: number
  username: string
  displayName: string
  levelName: string
  workerStatus: string
  acceptedOrderCount: number
  rewardAmount: number
  lastAcceptedAt: string | null
}

export function fetchAdminWorkerLeaderboard(
  period: AdminLeaderboardPeriod,
  limit = 50,
  range?: { from: string; to: string },
) {
  return apiGet<{
    period: AdminLeaderboardPeriod | 'custom'
    from: string | null
    to: string | null
    items: AdminWorkerLeaderboardEntry[]
  }>('/api/v1/admin/worker-platform/leaderboard', {
    period,
    limit,
    ...(range ? { from: range.from, to: range.to } : {}),
  })
}

export function fetchAdminWorkerPlatformSummary() {
  return apiGet<{
    pendingWorkerCount: number
    pendingMaterialCount: number
    openOrderCount: number
    queuedHallOrderCount: number
    hallMaxVisibleOrders: number
    inProgressOrderCount: number
  }>('/api/v1/admin/worker-platform/summary')
}

export function fetchAdminWorkerHallConfig() {
  return apiGet<WorkerHallConfig>('/api/v1/admin/worker-platform/hall-config')
}

export function saveAdminWorkerHallConfig(
  payload: Pick<WorkerHallConfig, 'maxVisibleOrders' | 'categoryMaxVisibleOrders'>,
) {
  return apiPost<WorkerHallConfig>('/api/v1/admin/worker-platform/hall-config', payload)
}

export function fetchAdminWorkerAnnouncement() {
  return apiGet<WorkerAnnouncementConfig>('/api/v1/admin/worker-platform/announcement')
}

export function saveAdminWorkerAnnouncement(payload: WorkerAnnouncementConfig) {
  return apiPost<WorkerAnnouncementConfig>('/api/v1/admin/worker-platform/announcement', payload)
}

export function fetchAdminWorkerCancelRequests(
  status: 'pending' | 'approved' | 'rejected' = 'pending',
) {
  return apiGet<{ items: WorkerCancelRequest[] }>('/api/v1/admin/worker-platform/cancel-requests', {
    status,
  })
}

export function reviewAdminWorkerCancelRequest(
  requestId: number,
  payload: { approved: boolean; reviewNote: string },
) {
  return apiPost<{
    request: WorkerCancelRequest
    order: WorkOrder
    approved: boolean
    releasedDepositAmount: number
    levelChanged: boolean
    accountDisabled: boolean
  }>(`/api/v1/admin/worker-platform/cancel-requests/${requestId}/review`, payload)
}

export function fetchAdminWorkerOrderFeedbacks(status: 'pending' | 'resolved' = 'pending') {
  return apiGet<{ items: WorkerOrderFeedback[] }>('/api/v1/admin/worker-platform/feedbacks', {
    status,
  })
}

export function resolveAdminWorkerOrderFeedback(feedbackId: number, payload: { reply: string }) {
  return apiPost<{ feedback: WorkerOrderFeedback; order: WorkOrder }>(
    `/api/v1/admin/worker-platform/feedbacks/${feedbackId}/resolve`,
    payload,
  )
}

export function fetchAdminWorkerLevels() {
  return apiGet<{ items: WorkerLevel[] }>('/api/v1/admin/worker-platform/levels')
}

export function fetchAdminWorkCategories() {
  return apiGet<{ items: WorkCategory[] }>('/api/v1/admin/worker-platform/categories')
}

export function saveAdminWorkCategory(payload: {
  categoryKey: string
  name: string
  sortOrder?: number
  status?: string
}) {
  return apiPost<{ category: WorkCategory }>('/api/v1/admin/worker-platform/categories', payload)
}

export function deleteAdminWorkCategory(categoryId: number) {
  return apiDelete<{ deleted: boolean }>(`/api/v1/admin/worker-platform/categories/${categoryId}`)
}

export function deleteAdminWorkerLevel(levelId: number) {
  return apiDelete<{ deleted: boolean }>(`/api/v1/admin/worker-platform/levels/${levelId}`)
}

export function saveAdminWorkerLevel(payload: {
  levelKey: string
  name: string
  depositFreeAmount?: number
  maxActiveOrders?: number
  upgradeThreshold?: number
  autoAcceptWithoutEvidence?: boolean
  visibleDelaySeconds?: number
  status?: string
}) {
  return apiPost<{ level: WorkerLevel }>('/api/v1/admin/worker-platform/levels', payload)
}

export function fetchAdminWorkerUsers(params?: Record<string, unknown>) {
  return apiGet<WorkerListResponse<WorkerUser>>('/api/v1/admin/worker-platform/workers', params)
}

export function fetchAdminWorkerDetail(workerId: number | string) {
  return apiGet<AdminWorkerDetail>(`/api/v1/admin/worker-platform/workers/${workerId}/detail`)
}

export function fetchAdminWorkerWalletLedgers(
  workerId: number | string,
  params?: Record<string, unknown>,
) {
  return apiGet<WorkerListResponse<WorkerWalletLedger>>(
    `/api/v1/admin/worker-platform/workers/${workerId}/wallet-ledgers`,
    params,
  )
}

export function fetchAdminWorkerDepositUnfreezes(
  workerId: number | string,
  params?: Record<string, unknown>,
) {
  return apiGet<WorkerListResponse<WorkerDepositUnfreeze>>(
    `/api/v1/admin/worker-platform/workers/${workerId}/deposit-unfreezes`,
    params,
  )
}

export function fetchAdminWorkProductRules(params?: Record<string, unknown>) {
  return apiGet<{
    items: WorkProductRule[]
    pagination: { page: number; pageSize: number; total: number }
    categoryCounts: Array<{ categoryId: number | null; total: number }>
  }>('/api/v1/admin/worker-platform/product-rules', params)
}

export function saveAdminWorkProductRule(payload: {
  ruleId?: number
  ruleKey: string
  provider?: string
  platform?: string
  shopId?: string
  skuCode?: string
  productName?: string
  matchType?: string
  sellerId?: string
  itemId?: string
  relItemId?: string
  skuId?: string
  relSkuId?: string
  itemTitle?: string
  skuNick?: string
  itemTitleMatchType?: 'contains' | 'exact'
  skuNickMatchType?: 'contains' | 'exact'
  match?: {
    sellerId?: string
    itemId?: string
    relItemId?: string
    skuId?: string
    relSkuId?: string
    itemTitle?: string
    skuNick?: string
    itemTitleMatchType?: 'contains' | 'exact'
    skuNickMatchType?: 'contains' | 'exact'
  }
  categoryId?: number
  enabled?: boolean
  autoCreate?: boolean
  rewardAmount?: number
  unitPrice?: number
  sharingEnabled?: boolean
  sharingAutoFromOrder?: boolean
  sharingTotalQuantity?: number
  sharingUnitReward?: number
  sharingTotalAmount?: number
  timeoutMinutes?: number
  timeoutPolicy?: string
  acceptanceMode?: 'standard' | 'friend_gift' | string
  giftCooldownHours?: number
  giftCooldownMinutes?: number
  fieldsText?: string
  sortOrder?: number
}) {
  return apiPost<{ rule: WorkProductRule }>('/api/v1/admin/worker-platform/product-rules', payload)
}

export function syncAdminWorkProductRulePrice(ruleId: number) {
  return apiPost<{
    candidateCount: number
    updatedCount: number
    updatedNormalCount: number
    updatedPartialSharingCount: number
    skippedInvalidPricingCount: number
    skippedUnchangedCount: number
    skippedUnavailableCount: number
  }>(`/api/v1/admin/worker-platform/product-rules/${ruleId}/sync-price`)
}

export function deleteAdminWorkProductRule(ruleId: number) {
  return apiDelete<{ deleted: boolean }>(`/api/v1/admin/worker-platform/product-rules/${ruleId}`)
}

export function fetchAdminWorkProductRuleMappings(params?: Record<string, unknown>) {
  return apiGet<{
    items: WorkProductRuleMapping[]
    pagination?: { page: number; pageSize: number; total: number }
  }>('/api/v1/admin/worker-platform/product-mappings', params)
}

export function saveAdminWorkProductRuleMapping(payload: {
  mappingId?: number
  ruleId: number
  sellerIds: string[]
  relItemId?: string
  itemTitle?: string
  relSkuId?: string
  skuNick?: string
  skuMatchMode?: 'fuzzy' | 'exact'
  mappingType: 'product_default' | 'sku_exact' | 'sku_series'
  enabled?: boolean
}) {
  return apiPost<{ mapping: WorkProductRuleMapping }>(
    '/api/v1/admin/worker-platform/product-mappings',
    payload,
  )
}

export function deleteAdminWorkProductRuleMapping(mappingId: number) {
  return apiDelete<{ deleted: boolean }>(
    `/api/v1/admin/worker-platform/product-mappings/${mappingId}`,
  )
}

export function fetchAdminWorkerProductMatchConfig() {
  return apiGet<WorkerProductMatchConfig>('/api/v1/admin/worker-platform/product-match-config')
}

export function saveAdminWorkerProductMatchConfig(payload: WorkerProductMatchConfig) {
  return apiPost<WorkerProductMatchConfig>(
    '/api/v1/admin/worker-platform/product-match-config',
    payload,
  )
}

export function fetchAdminKuaishouMatchSources(limit = 100) {
  return apiGet<{ items: KuaishouMatchSource[] }>(
    '/api/v1/admin/worker-platform/product-match-sources',
    {
      limit,
    },
  )
}

export function testAdminKuaishouProductMatch(rawPayload: string) {
  return apiPost<{
    context: Record<string, string>
    status: 'matched' | 'unmatched' | 'ambiguous'
    mappingId: number | null
    rule: WorkProductRule | null
    candidates: Array<{ ruleKey: string; score: number; mappingId: number | null }>
  }>('/api/v1/admin/worker-platform/product-match-test', { rawPayload })
}

export function fetchAdminWorkProductMatchLogs(params?: Record<string, unknown>) {
  return apiGet<WorkerListResponse<WorkProductMatchLog>>(
    '/api/v1/admin/worker-platform/product-match-logs',
    params,
  )
}

export function reprocessAdminKuaishouWorkOrderMatches(limit = 100) {
  return apiPost<{ scannedCount: number; createdCount: number; skippedCount: number }>(
    '/api/v1/admin/worker-platform/orders/reprocess-matches',
    { limit },
  )
}

export function reviewAdminWorkerUser(
  workerId: number,
  payload: {
    status: string
    reviewNote?: string
    freezeReason?: string
    levelId?: number
    workerType?: string
  },
) {
  return apiPost<{ worker: WorkerUser }>(
    `/api/v1/admin/worker-platform/workers/${workerId}/review`,
    payload,
  )
}

export function saveAdminWorkerPersonalDepositFreeAmount(
  workerId: number,
  payload: { depositFreeAmount: number | null },
) {
  return apiPost<{ worker: WorkerUser }>(
    `/api/v1/admin/worker-platform/workers/${workerId}/personal-deposit-free-amount`,
    payload,
  )
}

export function resetAdminWorkerPassword(workerId: number, payload: { password: string }) {
  return apiPost<{ worker: WorkerUser; reloginRequired: boolean }>(
    `/api/v1/admin/worker-platform/workers/${workerId}/reset-password`,
    payload,
  )
}

export function fetchAdminWorkerWithdrawalAccounts(workerId: number) {
  return apiGet<{ worker: WorkerUser; items: AdminWorkerWithdrawalAccount[] }>(
    `/api/v1/admin/worker-platform/workers/${workerId}/withdrawal-accounts`,
  )
}

export function saveAdminWorkerWithdrawalAccount(
  workerId: number,
  accountChannel: string,
  payload: {
    accountName: string
    accountNo?: string
    alipayQrCodeImages?: UploadedFile[]
    wechatQrCodeImages?: UploadedFile[]
  },
) {
  return apiPost<{ account: AdminWorkerWithdrawalAccount }>(
    `/api/v1/admin/worker-platform/workers/${workerId}/withdrawal-accounts/${accountChannel}`,
    payload,
  )
}

export function assignAdminWorkOrderToWorker(workOrderId: number, payload: { workerId: number }) {
  return apiPost<{
    order: WorkOrder
    voucherConsume: WorkOrderVoucherConsumeResult
  }>(`/api/v1/admin/worker-platform/orders/${workOrderId}/assign`, payload)
}

export function unassignAdminWorkOrder(workOrderId: number) {
  return apiPost<{ order: WorkOrder }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/unassign`,
  )
}

export function cancelAdminWorkOrder(
  workOrderId: number,
  payload: {
    action: 'return_to_hall' | 'cancel_order'
    reason?: string
  },
) {
  return apiPost<{ order: WorkOrder }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/cancel`,
    payload,
  )
}

export function creditAdminWorkerWallet(
  workerId: number,
  payload: { amount: number; note?: string },
) {
  return apiPost<{ wallet: Record<string, unknown> }>(
    `/api/v1/admin/worker-platform/workers/${workerId}/wallet-credit`,
    payload,
  )
}

export function fetchAdminWorkerFinanceConfig() {
  return apiGet<WorkerFinanceConfig>('/api/v1/admin/worker-platform/finance-config')
}

export function saveAdminWorkerFinanceConfig(payload: {
  depositUnfreezeDays?: number
  rewardUnfreezeEnabled?: boolean
  recharge?: {
    enabled?: boolean
    channelName?: string
    accountName?: string
    accountNo?: string
    qrCodeImage?: unknown
    instructions?: string
  }
  adminContact?: {
    wechatQrCodeImage?: unknown
  }
  withdraw?: {
    enabled?: boolean
    instructions?: string
  }
}) {
  return apiPost<WorkerFinanceConfig>('/api/v1/admin/worker-platform/finance-config', payload)
}

export function fetchAdminWorkerPlatformNotificationConfig() {
  return apiGet<WorkerPlatformNotificationConfig>(
    '/api/v1/admin/worker-platform/notification-config',
  )
}

export function saveAdminWorkerPlatformNotificationConfig(
  payload: WorkerPlatformNotificationConfig,
) {
  return apiPost<WorkerPlatformNotificationConfig>(
    '/api/v1/admin/worker-platform/notification-config',
    payload,
  )
}

export function fetchAdminWorkerFinanceRequests(params?: Record<string, unknown>) {
  return apiGet<
    WorkerListResponse<WorkerFinanceRequest> & {
      summary?: {
        channels: { channel: string; count: number; amount: number }[]
        totalCount: number
        totalAmount: number
      }
    }
  >('/api/v1/admin/worker-platform/finance-requests', params)
}

export function reviewAdminWorkerFinanceRequest(
  requestId: number,
  payload: { status: 'approved' | 'rejected' | 'cancelled'; reviewedNote?: string; note?: string },
) {
  return apiPost<{ request: WorkerFinanceRequest }>(
    `/api/v1/admin/worker-platform/finance-requests/${requestId}/review`,
    payload,
  )
}

export function fetchAdminWorkOrders(params?: Record<string, unknown>) {
  return apiGet<
    WorkerListResponse<WorkOrder> & {
      statistics: WorkOrderStatistics
    }
  >('/api/v1/admin/worker-platform/orders', params)
}

export function fetchAdminAfterSalesCases(params?: Record<string, unknown>) {
  return apiGet<WorkerListResponse<WorkerAfterSalesCase>>(
    '/api/v1/admin/worker-platform/after-sales-cases',
    params,
  )
}

export function fetchAdminAfterSalesCaseEvents(caseId: number) {
  return apiGet<{ items: WorkerAfterSalesCaseEvent[] }>(
    `/api/v1/admin/worker-platform/after-sales-cases/${caseId}/events`,
  )
}

export function createAdminAfterSalesCase(
  workOrderId: number,
  payload: {
    shareId?: number | null
    problemType?: string
    complaintNote: string
    files?: UploadedFile[]
  },
) {
  return apiPost<{ case: WorkerAfterSalesCase }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/after-sales-cases`,
    payload,
  )
}

export function resolveAdminAfterSalesCase(
  caseId: number,
  payload: {
    action: 'not_upheld' | 'remedied' | 'upheld'
    resolutionNote: string
    recoveryAmount?: number
  },
) {
  return apiPost<{
    case: WorkerAfterSalesCase
    refundedTotalAmount: number
    refundedRecoveries: Array<{ caseId: number; caseNo: string; amount: number }>
  }>(`/api/v1/admin/worker-platform/after-sales-cases/${caseId}/resolve`, payload)
}

export function fetchAdminWorkOrderEvents(workOrderId: number) {
  return apiGet<{ items: WorkOrderEvent[] }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/events`,
  )
}

export function fetchAdminMockCustomShops() {
  return apiGet<{ items: string[] }>('/api/v1/admin/worker-platform/orders/mock/custom-shops')
}

export function addAdminMockCustomShop(name: string) {
  return apiPost<string[]>('/api/v1/admin/worker-platform/orders/mock/custom-shops', {
    name,
  })
}

export function renameAdminMockCustomShop(name: string, newName: string) {
  return apiPut<string[]>('/api/v1/admin/worker-platform/orders/mock/custom-shops', {
    name,
    newName,
  })
}

export function deleteAdminMockCustomShop(name: string) {
  return apiDelete<string[]>(
    `/api/v1/admin/worker-platform/orders/mock/custom-shops?name=${encodeURIComponent(name)}`,
  )
}

export function createAdminMockWorkOrder(payload: {
  platformOrderId: string
  sellerId: string
  productName: string
  categoryId?: number
  rewardAmount: number
  paymentAmount: number
  materialComplete?: boolean
  acceptanceMode?: 'standard' | 'friend_gift' | string
}) {
  return apiPost<{ order: WorkOrder }>('/api/v1/admin/worker-platform/orders/mock', payload)
}

export function submitAdminWorkOrderMaterial(
  workOrderId: number,
  fields: Record<string, string>,
  screenshots?: UploadedFile[],
  rewardAmount?: number,
) {
  return apiPost<{ order: WorkOrder; complete: boolean }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/material`,
    { fields, screenshots, rewardAmount },
  )
}

export function publishAdminWorkOrder(workOrderId: number) {
  return apiPost<{
    order: WorkOrder
    voucherConsume: WorkOrderVoucherConsumeResult
    hallVisible: boolean
  }>(`/api/v1/admin/worker-platform/orders/${workOrderId}/publish`)
}

export function reopenAdminCancelledWorkOrder(workOrderId: number) {
  return apiPost<{ order: WorkOrder }>(`/api/v1/admin/worker-platform/orders/${workOrderId}/reopen`)
}

export function updateAdminWorkOrder(
  workOrderId: number,
  payload: {
    productName?: string
    platformOrderId?: string
    categoryId?: number | null
    rewardAmount?: number
    requiredDepositAmount?: number
    fieldsText?: string
    timeoutMinutes?: number
    timeoutPolicy?: string
  },
) {
  return apiPut<{ order: WorkOrder }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}`,
    payload,
  )
}

export function updateAdminWorkOrderNote(workOrderId: number, note: string) {
  return apiPut<{ order: WorkOrder }>(`/api/v1/admin/worker-platform/orders/${workOrderId}/note`, {
    note,
  })
}

export function deleteAdminWorkOrder(workOrderId: number) {
  return apiDelete<{ deleted: boolean }>(`/api/v1/admin/worker-platform/orders/${workOrderId}`)
}

export function unpublishAdminWorkOrder(workOrderId: number) {
  return apiPost<{ order: WorkOrder }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/unpublish`,
  )
}

export function pinAdminWorkOrder(workOrderId: number, pinned: boolean) {
  return apiPost<{ order: WorkOrder }>(`/api/v1/admin/worker-platform/orders/${workOrderId}/pin`, {
    pinned,
  })
}

export function fetchAdminWorkOrderSharing(workOrderId: number) {
  return apiGet<{ order: WorkOrder; shares: WorkOrderShare[] }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/sharing`,
  )
}

export function updateAdminWorkOrderSharing(
  workOrderId: number,
  payload: {
    enabled: boolean
    totalQuantity: number
    unitReward: number
    totalAmount?: number
  },
) {
  return apiPost<{ order: WorkOrder }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/sharing`,
    payload,
  )
}

export function markAdminWorkOrderProblem(workOrderId: number, note: string) {
  return apiPost<{ order: WorkOrder }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/problem`,
    { note },
  )
}

/** 好友赠送模式：核对打手资料并添加好友后确认，开始冷却倒计时 */
export function confirmAdminWorkOrderFriend(workOrderId: number) {
  return apiPost<{ order: WorkOrder }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/confirm-friend`,
  )
}

/** 好友赠送模式：客服人工确认冷却完成，立即允许打手提交验收。 */
export function completeAdminWorkOrderGiftCooldown(workOrderId: number) {
  return apiPost<{ order: WorkOrder }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/complete-gift-cooldown`,
  )
}

/** 好友赠送模式：重置打手资料，冷却与好友时间清零 */
export function resetAdminWorkOrderGiftMaterial(workOrderId: number, note?: string) {
  return apiPost<{ order: WorkOrder }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/reset-gift-material`,
    note ? { note } : {},
  )
}

export function resolveAdminProblemWorkOrder(
  workOrderId: number,
  payload: {
    action: 'return_to_worker' | 'reopen' | 'cancel_release' | 'cancel_deduct'
    note: string
  },
) {
  return apiPost<{ order: WorkOrder }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/problem/resolve`,
    payload,
  )
}

export function acceptAdminWorkOrder(workOrderId: number) {
  return apiPost<{ order: WorkOrder }>(`/api/v1/admin/worker-platform/orders/${workOrderId}/accept`)
}

export function acceptAdminWorkOrderShare(workOrderId: number, shareId: number) {
  return apiPost<{ order: WorkOrder; share: WorkOrderShare }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/shares/${shareId}/accept`,
  )
}

export function cancelAdminWorkOrderShare(
  workOrderId: number,
  shareId: number,
  payload: { reason?: string },
) {
  return apiPost<{
    order: WorkOrder
    share: WorkOrderShare
    releasedDepositAmount: number
  }>(`/api/v1/admin/worker-platform/orders/${workOrderId}/shares/${shareId}/cancel`, payload)
}

export function cancelAdminWorkOrderSharing(
  workOrderId: number,
  payload: {
    action: 'return_to_hall' | 'cancel_order'
    reason?: string
  },
) {
  return apiPost<{
    order: WorkOrder
    action: 'return_to_hall' | 'cancel_order'
    cancelledShareCount: number
    releasedDepositAmount: number
  }>(`/api/v1/admin/worker-platform/orders/${workOrderId}/sharing/cancel`, payload)
}

export function acceptAdminWorkOrders(workOrderIds: number[]) {
  return apiPost<{ orders: WorkOrder[] }>('/api/v1/admin/worker-platform/orders/accept-batch', {
    workOrderIds,
  })
}

export function deductAdminWorkOrderPendingDeposit(
  workOrderId: number,
  payload: { amount: number; note: string },
) {
  return apiPost<{ deductedAmount: number }>(
    `/api/v1/admin/worker-platform/orders/${workOrderId}/deduct-pending-deposit`,
    payload,
  )
}
