import { useQuery } from '@tanstack/react-query';
import { useIsAuthenticated } from '@/hooks';
import { profilesApi } from '../apis';
import { profileKeys } from '../keys';
import { PROFILE_STALE_TIME } from '../constants';

/** The signed-in customer's payer profile (emergency contact + name). `null` until created. */
export function useCustomerProfile() {
  const isAuthenticated = useIsAuthenticated();
  return useQuery({
    queryKey: profileKeys.customer(),
    queryFn: () => profilesApi.getCustomerProfile(),
    enabled: isAuthenticated,
    staleTime: PROFILE_STALE_TIME,
  });
}
