import { useMutation, useQueryClient } from '@tanstack/react-query'
import { createDataset, deleteDataset } from './api'
import type { CreateDatasetParams } from './types'
import { message } from 'antd'

// 创建
export function useCreateDataset() {
  const queryClient = useQueryClient()

  return useMutation({
    mutationFn: (data: CreateDatasetParams) => createDataset(data),
    onSuccess: () => {
      message.success('创建成功')
      queryClient.invalidateQueries({ queryKey: ['builtDataset'] })
    },
  })
}

// 删除
export function useDeleteDataset() {
  const queryClient = useQueryClient()

  return useMutation({
    mutationFn: (data: { id: string }) => deleteDataset(data),
    onSuccess: () => {
      message.success('删除成功')
      queryClient.invalidateQueries({ queryKey: ['builtDataset'] })
    },
  })
}
