import type {
  VideoDiscoveryDemandDetail,
  VideoDiscoveryDemandResponse,
} from '../types/videoDiscovery'

export async function fetchVideoDiscoveryDemands(
  bizDt?: string | null,
): Promise<VideoDiscoveryDemandResponse> {
  const query = bizDt ? `?biz_dt=${encodeURIComponent(bizDt)}` : ''
  const res = await fetch(`/api/video-discovery/demands${query}`)
  if (!res.ok) {
    throw new Error(`加载需求找片数据失败: ${res.status} ${res.statusText}`)
  }
  return res.json()
}

export async function fetchVideoDiscoveryDemand(
  demandGradeId: number,
): Promise<VideoDiscoveryDemandDetail> {
  const res = await fetch(`/api/video-discovery/demands/${demandGradeId}`)
  if (!res.ok) {
    throw new Error(`加载需求视频详情失败: ${res.status} ${res.statusText}`)
  }
  return res.json()
}
