import * as api from "../service/NotificationService";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";

export const useGetNotifications = () => {
  return useQuery({
    queryKey: ["notifications"],
    queryFn: api.getNotifications,
  });
};

export const useDeleteNotification = () => {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: api.deleteNotification,
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["notifications"] });
    },
  });
};

export const useReadAllNotifications = () => {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: api.readAll,
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["notifications"] });
      queryClient.invalidateQueries({ queryKey: ["notificationsCount"] });
    },
  });
};
