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

export const useGetJobs = (page: number = 1) => {
  return useQuery({
    queryKey: ["jobs", page],
    queryFn: () => api.getJobs(page),
  });
};

export const useCreateJob = () => {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: api.createJob,
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["jobs"] });
    },
  });
};

export const useDeleteJob = () => {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: api.deleteJob,
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["jobs"] });
    },
  });
};

export const useGetResumes = (page: number = 1) => {
  return useQuery({
    queryKey: ["resumes", page],
    queryFn: () => api.getResumes(page),
  });
};
