import { useQuery } from '@tanstack/react-query';
import { useIsAuthenticated } from '@/hooks';
import { verificationApi } from '../apis';
import { verificationKeys } from '../keys';
import { VERIFICATION_STATUS_STALE_TIME } from '../constants';

/**
 * The nurse's own verification checklist + aggregate status. **The single cached source B3 and B6 both
 * read** — one query, two views (checklist hub / under-review). Every submit/upload/run mutation
 * invalidates `verificationKeys.status()`, so the checklist re-renders from cache with no manual
 * refetch. A moderate `staleTime` avoids a refetch when the two screens mount in sequence.
 */
export function useVerificationStatus() {
  const isAuthenticated = useIsAuthenticated();
  return useQuery({
    queryKey: verificationKeys.status(),
    queryFn: () => verificationApi.getStatus(),
    enabled: isAuthenticated,
    staleTime: VERIFICATION_STATUS_STALE_TIME,
  });
}
