import apiClient from '../client'
import type { InferenceResponse } from '../types'

export interface ProcessDocumentOptions {
  extractLineItems?: boolean
}

// Longer timeout for inference - line items extraction can take 60+ seconds
const INFERENCE_TIMEOUT_MS = 120000

export const inferenceApi = {
  processDocument: async (
    file: File,
    options: ProcessDocumentOptions = {}
  ): Promise<InferenceResponse> => {
    const formData = new FormData()
    formData.append('file', file)

    if (options.extractLineItems) {
      formData.append('extract_line_items', 'true')
    }

    const { data } = await apiClient.post('/api/v1/infer', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
      timeout: INFERENCE_TIMEOUT_MS,
    })
    return data
  },
}
