import { useQuery } from '@tanstack/react-query';
import { useInject } from '@/lib/di/hooks/useInject';
import { LEAGUE_SERVICE_TOKEN } from '@/lib/di/tokens';
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';

export function useLeagueMemberships(leagueId: string, currentUserId: string) {
  const leagueService = useInject(LEAGUE_SERVICE_TOKEN);

  const queryResult = useQuery({
    queryKey: ['leagueMemberships', leagueId, currentUserId],
    queryFn: () => leagueService.getLeagueMemberships(leagueId),
    enabled: !!leagueId && !!currentUserId,
  });

  return enhanceQueryResult(queryResult);
}