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

export function useUpdateRubro() {
  const queryClient = useQueryClient()
  return useMutation({
    mutationFn: ({ id, data }: { id: number; data: UpdateRubroRequest }) => updateRubro(id, data),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['rubros'] })
    },
  })
}
