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

export const useGetRoles = (params?: api.GetRolesParams) => {
  return useQuery({
    queryKey: ["roles", params],
    queryFn: () => api.getRoles(params),
  });
};

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