import { useQuery } from '@tanstack/react-query';
import { useIsAuthenticated } from '@/hooks';
import type { PageParams } from '@/lib/api/types';
import { catalogApi } from '../apis';
import { catalogKeys } from '../keys';
import { MY_VARIANTS_STALE_TIME } from '../constants';

/**
 * The signed-in nurse's own offerings (active and inactive, active-first, paginated). Self-scoped
 * server-side — a nurse never sees another nurse's variants. A deliberate staleTime keeps the list
 * warm across remounts; every variant mutation invalidates it.
 */
export function useMyVariants(params?: PageParams) {
  const isAuthenticated = useIsAuthenticated();
  return useQuery({
    queryKey: catalogKeys.myVariants(params),
    queryFn: () => catalogApi.listMyVariants(params),
    enabled: isAuthenticated,
    staleTime: MY_VARIANTS_STALE_TIME,
  });
}
