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

export function useUpdateProductType() {
  const queryClient = useQueryClient()
  return useMutation({
    mutationFn: ({ id, data }: { id: number; data: UpdateProductTypeRequest }) =>
      updateProductType(id, data),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['product-types'] })
    },
  })
}
