import type { DemandGradeResponse, DemandGradeVideosResponse } from '../types/demand'

export async function fetchDemandGrade(bizDt?: string | null): Promise<DemandGradeResponse> {
  const query = bizDt ? `?biz_dt=${encodeURIComponent(bizDt)}` : ''
  const res = await fetch(`/api/demand-grade${query}`)
  if (!res.ok) {
    throw new Error(`加载需求分级失败: ${res.status} ${res.statusText}`)
  }
  return res.json()
}

export async function fetchDemandGradeVideos(
  demandGradeId: number,
): Promise<DemandGradeVideosResponse> {
  const res = await fetch(`/api/demand-grade/${demandGradeId}/videos`)
  if (!res.ok) {
    throw new Error(`加载关联视频失败: ${res.status} ${res.statusText}`)
  }
  return res.json()
}
