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

const useUnenrollFreeAgent = () => {
  const queryClient = useQueryClient();
  
  return useServerMutation({
    mutationFn: (data: { tournamentId: string, playerId: string }) => {
      return unenrollFreeAgent({ data });
    },
    onSuccess: (data, { tournamentId }) => {
      queryClient.invalidateQueries({ queryKey: tournamentKeys.free_agents(tournamentId) });
    },
    successMessage: 'You\'ve been removed as a free agent.',
  });
};

export default useUnenrollFreeAgent;
