import { apiGet, apiPost } from '@/lib/http'

export type DevMockStatus = {
  enabled: boolean
  nodeEnv: string
  defaultUid: string
  platforms: Array<{
    key: string
    name: string
    description: string
    steps: string[]
  }>
}

export type DevMockCreateResult = {
  platform: 'lewan' | 'feifei' | 'affiliate_dash'
  orderId: number
  orderNo: string
  taskId: number
  taskNo: string
  claimToken: string
  claimUrl: string
  frontendClaimUrl: string
  expectedUid: string
  step: string
  productName: string
  tips: string[]
  open91QueryHint: string
}

export type DevMockOpen91QueryResult = {
  endpoint: string
  requestBody: Record<string, unknown>
  curl: string
  response: unknown
}

export type DevMockKuaishouIndustryVoucherResult = {
  createdCount: number
  sellerId: string
  vouchers: Array<{
    voucherCode: string
    oid: string
    status: string
  }>
}

export function fetchDevMockStatus() {
  return apiGet<DevMockStatus>('/api/v1/admin/dev-mock/status')
}

export function createLewanDevMock(payload: {
  step?: string
  uid?: string
  orderNo?: string
  productNo?: string
}) {
  return apiPost<DevMockCreateResult>('/api/v1/admin/dev-mock/lewan', payload)
}

export function createFeifeiDevMock(payload: {
  step?: string
  uid?: string
  orderNo?: string
  productName?: string
  productCode?: string
  h5Url?: string
}) {
  return apiPost<DevMockCreateResult>('/api/v1/admin/dev-mock/feifei', payload)
}

export function createAffiliateDashDevMock(payload: {
  step?: string
  uid?: string
  orderNo?: string
  productName?: string
  productSku?: string
}) {
  return apiPost<DevMockCreateResult>('/api/v1/admin/dev-mock/affiliate-dash', payload)
}

export function createKuaishouIndustryVoucherDevMock(payload: { sellerId?: string } = {}) {
  return apiPost<DevMockKuaishouIndustryVoucherResult>(
    '/api/v1/admin/dev-mock/kuaishou-industry/vouchers',
    payload,
  )
}

export function buildOpen91QueryDevMock(payload: {
  orderNo: string
  execute?: boolean
  baseUrl?: string
}) {
  return apiPost<DevMockOpen91QueryResult>('/api/v1/admin/dev-mock/open91/query', payload)
}
