import axios from 'axios'
import type { QueryRequest, QueryResponse, IngestResponse } from '../types'

const BASE_URL: string = import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:8000/api/v1'

export const apiClient = axios.create({ baseURL: BASE_URL })

export const queryDocument = async (request: QueryRequest): Promise<QueryResponse> => {
  const resp = await apiClient.post<QueryResponse>('/query', request)
  return resp.data
}

export const ingestDocument = async (file: File): Promise<IngestResponse> => {
  const form = new FormData()
  form.append('file', file)
  const resp = await apiClient.post<IngestResponse>('/ingest', form, {
    headers: { 'Content-Type': 'multipart/form-data' },
  })
  return resp.data
}
