import { exportReport, type ReportExportFormat, type ReportRecord } from '@/api/ops/report'

export async function downloadReportFile(record: ReportRecord, format: ReportExportFormat): Promise<void> {
  const { blob, fileName } = await exportReport(record.id, format)
  const url = window.URL.createObjectURL(blob)
  const link = document.createElement('a')
  try {
    link.href = url
    link.download = fileName
    document.body.appendChild(link)
    link.click()
  } finally {
    link.remove()
    window.URL.revokeObjectURL(url)
  }
}
