import request from './request'

export interface UnstructuredFileItem {
  id: number
  original_name: string
  file_type: string
  file_size: number
  status: string
  analysis_result?: {
    matches: {
      rule_name: string
      category_code: string
      level_code: string
      snippet: string
      position: number
    }[]
    total_chars: number
  }
  created_at?: string
}

export function uploadUnstructuredFile(file: File) {
  const formData = new FormData()
  formData.append('file', file)
  return request.post('/unstructured/upload', formData, {
    headers: { 'Content-Type': 'multipart/form-data' },
  })
}

export function getUnstructuredFiles(params?: { page?: number; page_size?: number }) {
  return request.get('/unstructured/files', { params })
}

export function reprocessUnstructuredFile(id: number) {
  return request.post(`/unstructured/files/${id}/reprocess`)
}
