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

export function useSponsorLeagueDetail(leagueId: string) {
  const sponsorService = useInject(SPONSOR_SERVICE_TOKEN);

  const queryResult = useQuery({
    queryKey: ['sponsorLeagueDetail', leagueId],
    queryFn: async () => {
      const result = await sponsorService.getLeagueDetail(leagueId);
      if (result.isErr()) {
        throw result.getError();
      }
      return result.unwrap();
    },
    enabled: !!leagueId,
  });

  return enhanceQueryResult(queryResult);
}