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

export const useGetNotification = (status: "all" | "read" | "unread") => {
  return useInfiniteQuery({
    queryKey: ["notifications", status],
    queryFn: ({ pageParam = 1 }) => api.getNotifications(pageParam, status), // فراخوانی API برای گرفتن داده‌ها
    initialPageParam: 1, // صفحه اول به طور پیشفرض
    getNextPageParam: (lastPage) => {
      const currentPage = lastPage.data?.pager.page;
      const totalPages = lastPage.data?.pager.totalPages;

      return currentPage < totalPages ? currentPage + 1 : undefined;
    },
  });
};

export const useReadAll = () => {
  return useMutation({
    mutationFn: (_) => api.readAll(),
  });
};
