import type { LlmBillingOverview } from '../types/llmBilling'

export async function fetchLlmBillingOverview(params: {
  startDt?: string
  endDt?: string
  recentLimit?: number
} = {}): Promise<LlmBillingOverview> {
  const query = new URLSearchParams()
  if (params.startDt) query.set('start_dt', params.startDt)
  if (params.endDt) query.set('end_dt', params.endDt)
  if (params.recentLimit) query.set('recent_limit', String(params.recentLimit))
  const suffix = query.toString() ? `?${query.toString()}` : ''
  const res = await fetch(`/api/llm-billing/overview${suffix}`)
  if (!res.ok) {
    throw new Error(`加载 LLM 费用失败: ${res.status} ${res.statusText}`)
  }
  return res.json()
}
