import http from '@/utils/http'

const { request } = http

export interface HealthRecord {
  id?: string
  employeeName: string
  employeeId: string
  checkupDate: string
  hospital: string
  checkType: string
  result: string
  nextCheckupDate: string
  summary?: string
  suggestions?: string
  remarks?: string
  reportFiles?: any[]
}

export interface HealthRecordListParams {
  employeeName?: string
  employeeId?: string
  hospital?: string
  result?: string
  checkupDateStart?: string
  checkupDateEnd?: string
  current?: number
  size?: number
}

export interface HealthRecordListResponse {
  records: HealthRecord[]
  total: number
  current: number
  size: number
}

// 新增健康记录
export function createHealthRecord(data: HealthRecord) {
  return request({
    url: '/health-record',
    method: 'post',
    data
  })
}

// 查询健康记录列表
export function getHealthRecordList(params: HealthRecordListParams) {
  return request<HealthRecordListResponse>({
    url: '/health-record/list',
    method: 'get',
    params
  })
}

// 查询健康记录详情
export function getHealthRecordDetail(id: string) {
  return request<HealthRecord>({
    url: `/health-record/detail/${id}`,
    method: 'get'
  })
}

// 编辑健康记录
export function updateHealthRecord(id: string, data: HealthRecord) {
  return request({
    url: `/health-record/${id}`,
    method: 'put',
    data
  })
}

// 删除健康记录
export function deleteHealthRecord(id: string) {
  return request({
    url: `/health-record/${id}`,
    method: 'delete'
  })
}

// 上传体检报告
export function uploadHealthReport(file: File, recordId: string) {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('recordId', recordId)
  
  return request({
    url: '/health-record/upload-report',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 下载体检报告
export function downloadHealthReport(fileId: string) {
  return request({
    url: `/health-record/download-report/${fileId}`,
    method: 'get',
    responseType: 'blob'
  })
}

// 获取员工健康记录历史
export function getEmployeeHealthHistory(employeeId: string) {
  return request<HealthRecord[]>({
    url: `/health-record/employee/${employeeId}`,
    method: 'get'
  })
}

// 导出健康记录
export function exportHealthRecords(params: HealthRecordListParams) {
  return request({
    url: '/health-record/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// 安排体检
export function scheduleHealthCheck(data: {
  employeeIds: string[]
  checkupDate: string
  hospital: string
  checkType: string
}) {
  return request({
    url: '/health-record/schedule',
    method: 'post',
    data
  })
} 