/**
 * @ai-summary React Query hook for user status (email verification + onboarding)
 * @ai-context Used by CallbackPage to determine routing after Auth0 callback
 */

import { useQuery } from '@tanstack/react-query';
import { useAuth0 } from '@auth0/auth0-react';
import { authApi } from '../../features/auth/api/auth.api';
import { UserStatusResponse } from '../../features/auth/types/auth.types';

interface UseUserStatusOptions {
  enabled?: boolean;
}

export const useUserStatus = (options?: UseUserStatusOptions) => {
  const { isAuthenticated, isLoading: isAuthLoading } = useAuth0();

  return useQuery<UserStatusResponse>({
    queryKey: ['userStatus'],
    queryFn: authApi.getUserStatus,
    enabled: (options?.enabled !== false) && isAuthenticated && !isAuthLoading,
    retry: 2,
    staleTime: 30000, // Cache for 30 seconds
  });
};
