import { useQuery } from '@tanstack/react-query';
import { adminApi } from '../apis';
import { adminKeys } from '../keys';
import { ADMIN_CONFIG_STALE_TIME, ADMIN_GC_TIME } from '../constants';

/** The RBAC role grants (all, or scoped to one user). Deferred-if-missing — mock-primary (REQ-031). */
export function useAdminRoles(userId?: number) {
  return useQuery({
    queryKey: adminKeys.roleList(userId),
    queryFn: () => adminApi.listRoles(userId),
    staleTime: ADMIN_CONFIG_STALE_TIME,
    gcTime: ADMIN_GC_TIME,
  });
}
