import { useMutation, useQueryClient } from '@tanstack/react-query'
import { message } from 'antd'
import { processData } from './api'
import type { ProcessDataParams } from './types'
import { useProcessProgressQuery } from '@/hooks/useQuery'

// 处理数据
export function useProcessData() {
  const queryClient = useQueryClient()
  const { data, start, remove } = useProcessProgressQuery({ function_name: 'logic' })

  const query = useMutation({
    mutationFn: (data: ProcessDataParams) => {
      start()
      return processData(data)
    },
    onSuccess: () => {
      message.success('处理完成')
      queryClient.invalidateQueries({ queryKey: ['data'] })
    },
  })
  return { ...query, progress: data.progress, message: data.message, remove }
}
