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

export const useGetNotifications = (
  params?: Record<string, string | number>
) => {
  return useQuery({
    queryKey: ["notifications", params],
    queryFn: () => api.getNotifications(params),
  });
};

export const useUpdateNotification = () => {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: ({
      id,
      channels,
    }: {
      id: string;
      channels: ("sms" | "push" | "in-app")[];
    }) => api.updateNotification(id, channels),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["notifications"] });
    },
  });
};
