import { api } from "@/lib/api-client";

export const reportService = {
  downloadPdf: async (attemptId: number): Promise<void> => {
    const response = await fetch(`/api/reports/exam/${attemptId}/pdf`, {
      headers: {
        Authorization: `Bearer ${localStorage.getItem("encoach_token")}`,
      },
    });
    if (!response.ok) throw new Error("Failed to generate report");
    const blob = await response.blob();
    const url = window.URL.createObjectURL(blob);
    const link = document.createElement("a");
    link.href = url;
    link.download = `exam-report-${attemptId}.pdf`;
    link.click();
    window.URL.revokeObjectURL(url);
  },
};
