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

/**
 * The internal support-alert worklist, filtered by type/status/owner + paginated. **Internal-only** — this
 * query is admin-scoped and its data never reaches a non-admin surface (phase §5). Filters + page key the cache.
 */
export function useSupportAlerts(filters: SupportAlertFilters, page = 1) {
  return useQuery({
    queryKey: adminKeys.supportAlertList(filters, { page, pageSize: ADMIN_PAGE_SIZE }),
    queryFn: () => adminApi.listSupportAlerts(filters, { page, pageSize: ADMIN_PAGE_SIZE }),
    staleTime: ADMIN_ALERTS_STALE_TIME,
    gcTime: ADMIN_GC_TIME,
    placeholderData: keepPreviousData,
  });
}
