import React from 'react'
import { QueryClient, QueryClientProvider, useMutation } from '@tanstack/react-query'
import { queryDocument, ingestDocument } from './api'
import type { QueryRequest, QueryResponse, IngestResponse } from '../types'

export const queryClient = new QueryClient()

export const useQueryDocument = () => {
  return useMutation<QueryResponse, Error, QueryRequest>({
    mutationFn: queryDocument,
  })
}

export const useIngestDocument = () => {
  return useMutation<IngestResponse, Error, File>({
    mutationFn: ingestDocument,
  })
}

export const AppQueryProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
  return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
}
