import { apiDelete, apiGet, apiPost } from '@/lib/http'
import type { ClaimDetailData } from '@/types/claim'
import type { TencentLoginType } from '@/types/tencent/session'

export function fetchClaimDetail(token: string) {
  return apiGet<ClaimDetailData>(`/api/v1/claim/${token}`)
}

export function createClaimSession(
  token: string,
  loginType: TencentLoginType,
  options: { forceRecreate?: boolean } = {},
) {
  return apiPost<ClaimDetailData>(`/api/v1/claim/${token}/session`, {
    loginType,
    forceRecreate: Boolean(options.forceRecreate),
  })
}

export function fetchClaimSessionSummary(token: string) {
  return apiGet<ClaimDetailData>(`/api/v1/claim/${token}/session/summary`)
}

export function verifyKuaishouCloudClaimTicket(
  token: string,
  payload: {
    ticketCode: string
  },
) {
  return apiPost<ClaimDetailData>(`/api/v1/claim/${token}/kuaishou-cloud/verify-ticket`, payload)
}

export function confirmKuaishouCloudClaimRole(token: string) {
  return apiPost<ClaimDetailData>(`/api/v1/claim/${token}/kuaishou-cloud/confirm-role`, {})
}

export function redeemKuaishouCloudClaim(token: string) {
  return apiPost<ClaimDetailData>(`/api/v1/claim/${token}/kuaishou-cloud/redeem`, {})
}

export function refreshClaimSession(token: string) {
  return apiPost<ClaimDetailData>(`/api/v1/claim/${token}/session/refresh`, {})
}

export function removeClaimSession(token: string) {
  return apiDelete<ClaimDetailData>(`/api/v1/claim/${token}/session`)
}

export function confirmClaimRole(token: string) {
  return apiPost<ClaimDetailData>(`/api/v1/claim/${token}/confirm-role`, { confirm: true })
}

export function redeemClaim(token: string) {
  return apiPost<ClaimDetailData>(`/api/v1/claim/${token}/redeem`, {})
}
