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

export function useAddProductPrice(productId: number) {
  const queryClient = useQueryClient()
  return useMutation({
    mutationFn: (payload: AddProductPriceRequest) => addProductPrice(productId, payload),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['products', productId, 'prices'] })
    },
  })
}
