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

export function useCreateProduct() {
  const queryClient = useQueryClient()
  return useMutation({
    mutationFn: (payload: CreateProductRequest) => createProduct(payload),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['products'] })
    },
  })
}
