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

/** All `platform_configs` rows (paginated). Near-static reference data → long `staleTime`. */
export function usePlatformConfigs(page = 1) {
  return useQuery({
    queryKey: adminKeys.configList({ page, pageSize: ADMIN_PAGE_SIZE }),
    queryFn: () => adminApi.listConfigs({ page, pageSize: ADMIN_PAGE_SIZE }),
    staleTime: ADMIN_CONFIG_STALE_TIME,
    gcTime: ADMIN_GC_TIME,
    placeholderData: keepPreviousData,
  });
}
