import { apiDelete, apiGet, apiPost } from '@/lib/http'
import type { AdminInventorySkuSuggestion, AdminManualRedeemDetail } from '@/types/admin'

export function fetchAdminManualRedeemSkuSuggestions(params?: Record<string, unknown>) {
  return apiGet<{ items: AdminInventorySkuSuggestion[] }>(
    '/api/v1/admin/manual-redeem/sku-suggestions',
    params,
  )
}

export function createAdminManualRedeemTask(payload: {
  proofValue: string
  skuCode: string
  skuName?: string
  remark?: string
}) {
  return apiPost<AdminManualRedeemDetail>('/api/v1/admin/manual-redeem', payload)
}

export function fetchAdminManualRedeemDetail(taskId: number | string) {
  return apiGet<AdminManualRedeemDetail>(`/api/v1/admin/manual-redeem/${taskId}`)
}

export function createAdminManualRedeemSession(
  taskId: number | string,
  payload: { loginType: string; forceRecreate?: boolean },
) {
  return apiPost<AdminManualRedeemDetail>(`/api/v1/admin/manual-redeem/${taskId}/session`, payload)
}

export function fetchAdminManualRedeemSessionSummary(taskId: number | string) {
  return apiGet<AdminManualRedeemDetail>(`/api/v1/admin/manual-redeem/${taskId}/session/summary`)
}

export function refreshAdminManualRedeemSession(taskId: number | string) {
  return apiPost<AdminManualRedeemDetail>(
    `/api/v1/admin/manual-redeem/${taskId}/session/refresh`,
    {},
  )
}

export function removeAdminManualRedeemSession(taskId: number | string) {
  return apiDelete<AdminManualRedeemDetail>(`/api/v1/admin/manual-redeem/${taskId}/session`)
}

export function confirmAdminManualRedeemRole(taskId: number | string) {
  return apiPost<AdminManualRedeemDetail>(`/api/v1/admin/manual-redeem/${taskId}/confirm-role`, {})
}

export function redeemAdminManualRedeem(taskId: number | string) {
  return apiPost<AdminManualRedeemDetail>(`/api/v1/admin/manual-redeem/${taskId}/redeem`, {})
}

export function closeAdminManualRedeemTask(taskId: number | string) {
  return apiPost<AdminManualRedeemDetail>(`/api/v1/admin/manual-redeem/${taskId}/close`, {})
}
