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

  const queryResult = useQuery({
    queryKey: ['sponsorBilling', sponsorId],
    queryFn: async () => {
      const result = await (sponsorService as any).getBilling(sponsorId);
      if (result.isErr()) {
        throw new Error(result.getError().message);
      }
      return result.unwrap();
    },
    enabled: !!sponsorId,
  });

  return enhanceQueryResult(queryResult);
}
