import { apiGet, apiPost } from '@/lib/http'
import type {
  AdminKuaishouIndustryAuthorizationCodePayload,
  AdminKuaishouIndustryConfigResponse,
  AdminKuaishouIndustryExchangeCodeResponse,
  AdminKuaishouIndustryRefreshTokenResponse,
  AdminKuaishouIndustrySourceConfig,
} from '@/types/admin'

export function fetchAdminKuaishouIndustrySourceConfig() {
  return apiGet<AdminKuaishouIndustryConfigResponse>(
    '/api/v1/admin/platform-config/kuaishou-industry-source',
  )
}

export function saveAdminKuaishouIndustrySourceConfig(payload: AdminKuaishouIndustrySourceConfig) {
  return apiPost<AdminKuaishouIndustryConfigResponse>(
    '/api/v1/admin/platform-config/kuaishou-industry-source',
    payload,
  )
}

export function refreshAdminKuaishouIndustryAccessToken(payload: { sellerId?: string } = {}) {
  return apiPost<AdminKuaishouIndustryRefreshTokenResponse>(
    '/api/v1/admin/platform-config/kuaishou-industry-source/refresh-token',
    payload,
  )
}

export function exchangeAdminKuaishouIndustryAuthorizationCode(
  payload: AdminKuaishouIndustryAuthorizationCodePayload,
) {
  return apiPost<AdminKuaishouIndustryExchangeCodeResponse>(
    '/api/v1/admin/platform-config/kuaishou-industry-source/exchange-code',
    payload,
  )
}
