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

const useAdminEnrollPlayer = () => {
  const queryClient = useQueryClient();

  return useServerMutation({
    mutationFn: (data: { tournamentId: string, playerId: string }) => {
      return adminEnrollPlayer({ data });
    },
    onSuccess: (data, { tournamentId }) => {
      queryClient.invalidateQueries({ queryKey: tournamentKeys.free_agents(tournamentId) });
      queryClient.invalidateQueries({ queryKey: tournamentKeys.details(tournamentId) });
    },
    successMessage: "Player enrolled successfully",
  });
};

export default useAdminEnrollPlayer;
