import { API_BASE, fetchWithAuth } from "./client";

export const reportsApi = {
  exportCSV: (token: string, queryId?: string) => {
    const query = queryId ? `?query_id=${queryId}` : "";
    return fetchWithAuth(`/api/v1/reports/export/csv${query}`, {}, token);
  },
  exportPDF: async (token: string, queryId?: string) => {
    const query = queryId ? `?query_id=${queryId}` : "";
    const res = await fetch(`${API_BASE}/api/v1/reports/export/pdf${query}`, {
      headers: { Authorization: `Bearer ${token}` },
    });
    if (!res.ok) throw new Error("导出失败");
    return res.blob();
  },
};
