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

export const useGetSchedules = (params?: Record<string, unknown>) => {
  return useQuery({
    queryKey: ["schedules", params],
    queryFn: () => api.getSchedules(params),
  });
};

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

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