import * as api from "../service/PagerService";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import type { PagerStatus } from "../enum/Enum";

export const useGetPagers = () => {
  return useQuery({
    queryKey: ["pagers"],
    queryFn: api.getPagers,
  });
};

export const useUpdatePagerStatus = () => {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: ({ id, status }: { id: string; status: PagerStatus }) =>
      api.updatePagerStatus(id, status),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["pagers"] });
    },
  });
};
