import request from './request'

export interface ReportStats {
  total: number
  auto: number
  manual: number
  reviewed: number
  level_distribution: {
    name: string
    code: string
    count: number
  }[]
}

export function getReportStats() {
  return request.get('/reports/stats')
}

export function downloadReport(projectId: number, format: string = 'docx') {
  const token = localStorage.getItem('dp_token')
  const url = `/api/v1/reports/projects/${projectId}/download?format=${format}`
  const a = document.createElement('a')
  a.href = url
  a.download = `report_project_${projectId}.${format === 'excel' ? 'xlsx' : 'docx'}`
  if (token) {
    a.setAttribute('data-token', token)
  }
  document.body.appendChild(a)
  a.click()
  document.body.removeChild(a)
}

export function getReportSummary(projectId: number) {
  return request.get(`/reports/projects/${projectId}/summary`)
}
