"use client";

import { useQuery } from "@tanstack/react-query";

import notificationService from "@/app/(dashboard)/notifications/services/notification.service";
import { notificationKeys } from "@/app/(dashboard)/notifications/notification.keys";

interface Props {
  page?: number;
  per_page?: number;
  unread_only?: boolean;
}

export function useNotifications({
  page = 1,
  per_page = 10,
  unread_only = false,
}: Props) {
  return useQuery({
    queryKey: notificationKeys.list({
      page,
      per_page,
      unread_only,
    }),
    queryFn: async () => {
      const response = await notificationService.getNotifications({
        page,
        per_page,
        unread_only,
      });

      return response.data;
    },
  });
}