import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useInject } from '@/lib/di/hooks/useInject';
import { PENALTY_SERVICE_TOKEN } from '@/lib/di/tokens';

export function usePenaltyMutation() {
  const penaltyService = useInject(PENALTY_SERVICE_TOKEN);
  const queryClient = useQueryClient();

  const applyPenaltyMutation = useMutation({
    mutationFn: (command: unknown) => penaltyService.applyPenalty(command),
    onSuccess: () => {
      // Invalidate relevant queries to refresh data
      queryClient.invalidateQueries({ queryKey: ['leagueStewardingData'] });
      queryClient.invalidateQueries({ queryKey: ['penalties'] });
    },
  });

  return applyPenaltyMutation;
}