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

export const useGetNotification = (status: "all" | "seen" | "unseen") => {
  return useInfiniteQuery({
    queryKey: ["notifications", status],
    queryFn: ({ pageParam }) =>
      api.getNotifications(pageParam as string | undefined, status), // فراخوانی API برای گرفتن داده‌ها
    initialPageParam: undefined as string | undefined, // اولین درخواست بدون cursor
    getNextPageParam: (lastPage) => {
      return lastPage.nextCursor || undefined;
    },
  });
};

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

export const useGetUnseenCount = () => {
  return useQuery({
    queryKey: ["unseen-count"],
    queryFn: () => api.getUnseenCount(),
  });
};
