import { useMutation, useQueryClient } from '@tanstack/react-query'
import { updateProduct } from '../api/updateProduct'
import type { UpdateProductRequest } from '../types'

export function useUpdateProduct() {
  const queryClient = useQueryClient()
  return useMutation({
    mutationFn: ({ id, data }: { id: number; data: UpdateProductRequest }) =>
      updateProduct(id, data),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['products'] })
    },
  })
}
