import { useQueryClient } from "@tanstack/react-query";
import { useLingui } from "@lingui/react/macro";
import { useServerMutation } from "@/lib/tanstack-query/hooks";
import { adminUnenrollPlayer } from "@/features/tournaments/server";
import { tournamentKeys } from "../queries";

const useAdminUnenrollPlayer = () => {
  const queryClient = useQueryClient();
  const { t } = useLingui();

  return useServerMutation({
    mutationFn: (data: { tournamentId: string, playerId: string }) => {
      return adminUnenrollPlayer({ data });
    },
    onSuccess: (data, { tournamentId }) => {
      queryClient.invalidateQueries({ queryKey: tournamentKeys.free_agents(tournamentId) });
      queryClient.invalidateQueries({ queryKey: tournamentKeys.details(tournamentId) });
    },
    successMessage: t`Player removed successfully`,
  });
};

export default useAdminUnenrollPlayer;
