import { usePageDataMultiple } from '@/lib/page/usePageData';
import { useInject } from '@/lib/di/hooks/useInject';
import { LEAGUE_SERVICE_TOKEN, LEAGUE_MEMBERSHIP_SERVICE_TOKEN } from '@/lib/di/tokens';

export function useLeagueSponsorshipsPageData(leagueId: string, currentDriverId: string) {
  const leagueService = useInject(LEAGUE_SERVICE_TOKEN);
  const leagueMembershipService = useInject(LEAGUE_MEMBERSHIP_SERVICE_TOKEN);

  return usePageDataMultiple({
    league: {
      queryKey: ['leagueDetail', leagueId, currentDriverId],
      queryFn: () => leagueService.getLeagueDetailData(leagueId),
    },
    membership: {
      queryKey: ['leagueMembership', leagueId, currentDriverId],
      queryFn: () => leagueMembershipService.fetchLeagueMemberships(leagueId).then(() => {
        return leagueMembershipService.getMembership(leagueId, currentDriverId);
      }),
    },
  });
}