import { useQuery } from '@tanstack/react-query';
import { verificationApi } from '../apis';
import { verificationKeys } from '../keys';
import { TRUST_BADGE_GC_TIME, TRUST_BADGE_STALE_TIME } from '../constants';

/**
 * The public trust badge for a nurse (verified state + credential **types**, never numbers). Public
 * (`[AllowAnonymous]`) and long-lived — it changes only on a step decision / suspension / expiry — so a
 * generous `staleTime` keeps it warm across the nurse's own profile and (in f6) search + public profile,
 * which reuse this same query key. Pass `nurseId = undefined` to disable until the id is known.
 */
export function useNurseTrustBadge(nurseId: number | undefined) {
  return useQuery({
    queryKey: verificationKeys.badge(nurseId ?? -1),
    queryFn: () => verificationApi.getTrustBadge(nurseId as number),
    enabled: nurseId != null,
    staleTime: TRUST_BADGE_STALE_TIME,
    gcTime: TRUST_BADGE_GC_TIME,
  });
}
