import { apiGet, apiPost } from '@/lib/http'
import type {
  AdminKuaishouFeifeiConfig,
  AdminKuaishouFeifeiConfigResponse,
  AdminKuaishouFeifeiMatchResult,
  AdminKuaishouFeifeiOrderResult,
  AdminKuaishouFeifeiProductListResult,
  AdminKuaishouFeifeiProductSyncResult,
} from '@/types/admin'

export function fetchAdminKuaishouFeifeiConfig() {
  return apiGet<AdminKuaishouFeifeiConfigResponse>('/api/v1/admin/platform-config/kuaishou-feifei')
}

export function saveAdminKuaishouFeifeiConfig(payload: AdminKuaishouFeifeiConfig) {
  return apiPost<AdminKuaishouFeifeiConfigResponse>(
    '/api/v1/admin/platform-config/kuaishou-feifei',
    payload,
  )
}

export function matchAdminKuaishouFeifeiProduct(productName: string) {
  return apiPost<AdminKuaishouFeifeiMatchResult>(
    '/api/v1/admin/platform-config/kuaishou-feifei/match',
    { productName },
  )
}

export function fetchAdminKuaishouFeifeiProducts(payload: {
  page?: number
  perPage?: number
  status?: string
  supplyProductName?: string
}) {
  return apiPost<AdminKuaishouFeifeiProductListResult>(
    '/api/v1/admin/platform-config/kuaishou-feifei/products',
    payload,
  )
}

export function syncAdminKuaishouFeifeiProducts(
  payload: {
    status?: string
    supplyProductName?: string
  } = {},
) {
  return apiPost<AdminKuaishouFeifeiProductSyncResult>(
    '/api/v1/admin/platform-config/kuaishou-feifei/sync-products',
    payload,
  )
}

export function createAdminKuaishouFeifeiTestOrder(payload: {
  platformOrderNo: string
  productCode: string
  platformBuyNum?: number
  platformAmount?: number | null
  playerAccount?: string
  playerGameRegion?: string
  playerGameSrv?: string
  playerGameRole?: string
  submitPlayer?: boolean
  notifyUrl?: string
}) {
  return apiPost<AdminKuaishouFeifeiOrderResult>(
    '/api/v1/admin/platform-config/kuaishou-feifei/test-order',
    payload,
  )
}

export function queryAdminKuaishouFeifeiOrder(payload: {
  platformOrderNo?: string
  orderNo?: string
}) {
  return apiPost<AdminKuaishouFeifeiOrderResult>(
    '/api/v1/admin/platform-config/kuaishou-feifei/query-order',
    payload,
  )
}
