import type { CategoryTreeResponse } from '../types/category'

export async function fetchCategoryTree(
  bizDt?: string | null,
): Promise<CategoryTreeResponse> {
  const params = new URLSearchParams()
  if (bizDt) params.set('biz_dt', bizDt)
  const qs = params.toString()
  const res = await fetch(`/api/category-tree${qs ? `?${qs}` : ''}`)
  if (!res.ok) {
    throw new Error(`加载分类树失败: ${res.status} ${res.statusText}`)
  }
  return res.json()
}
