import { apiGet, apiPost } from '@/lib/http'
import type {
  AdminKuaishouEticketConsumeResult,
  AdminKuaishouEticketDetailResult,
  AdminKuaishouEticketShopInfoResult,
  AdminKuaishouEticketSourceConfig,
} from '@/types/admin'

export function fetchAdminKuaishouEticketSourceConfig() {
  return apiGet<{
    filePath: string
    source: AdminKuaishouEticketSourceConfig
  }>('/api/v1/admin/platform-config/kuaishou-eticket-source')
}

export function saveAdminKuaishouEticketSourceConfig(payload: AdminKuaishouEticketSourceConfig) {
  return apiPost<{
    filePath: string
    source: AdminKuaishouEticketSourceConfig
  }>('/api/v1/admin/platform-config/kuaishou-eticket-source', payload)
}

export function queryAdminKuaishouEticketDetail(payload: {
  baseUrl?: string
  shopId?: string
  cookie?: string
  eTicketId: string
}) {
  return apiPost<AdminKuaishouEticketDetailResult>(
    '/api/v1/admin/platform-config/kuaishou-eticket/query-detail',
    payload,
  )
}

export function queryAdminKuaishouEticketShopInfo(payload: {
  baseUrl?: string
  shopId?: string
  cookie?: string
}) {
  return apiPost<AdminKuaishouEticketShopInfoResult>(
    '/api/v1/admin/platform-config/kuaishou-eticket/query-shop-info',
    payload,
  )
}

export function consumeAdminKuaishouEticket(payload: {
  baseUrl?: string
  shopId?: string
  cookie?: string
  eTicketId: string
  oid?: string
  formToken?: string
  num?: number
  storeId?: string
}) {
  return apiPost<AdminKuaishouEticketConsumeResult>(
    '/api/v1/admin/platform-config/kuaishou-eticket/consume',
    payload,
  )
}
