// [REQ T2]  Custom hooks – useCreateReservation enkapsuluje useMutation + invalidateQueries
// [REQ D7]  React Query – useMutation z onSuccess invaliduje cache /reservations
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { createReservation } from '../api/reservations';

export const useCreateReservation = ({ onSuccess, onError } = {}) => {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: createReservation,
    onSuccess: (data) => {
      queryClient.invalidateQueries({ queryKey: ['reservations'] });
      onSuccess?.(data);
    },
    onError,
  });
};
