// [REQ T2]  Custom hooks – useUpdateReservation enkapsuluje useMutation PATCH
// [REQ D7]  React Query – useMutation do zmiany statusu i terminu rezerwacji
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { updateReservation } from '../api/reservations';

export const useUpdateReservation = (options = {}) => {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: ({ id, patch }) => updateReservation(id, patch),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['reservations'] });
      options.onSuccess?.();
    },
    onError: options.onError,
  });
};
