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

export function useSchedulePriceChange(id: number) {
  const queryClient = useQueryClient()
  return useMutation({
    mutationFn: (payload: SchedulePriceChangeRequest) => schedulePriceChange(id, payload),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['chargeableChars', 'list'] })
      queryClient.invalidateQueries({ queryKey: ['chargeableChars', id] })
    },
  })
}
