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 useSponsorDashboard(sponsorId: string) {
  const sponsorService = useInject(SPONSOR_SERVICE_TOKEN);

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

  return enhanceQueryResult(queryResult);
}