import { apiRequest } from '@/shared/api/httpClient';
import type { TenantChild } from '@/shared/types/scope';

/**
 * Child tenants the user can drill into below a parent (or below their own
 * tenant when omitted): org → schools → campuses → classes.
 */
export function getScopeChildren(
  parentLevel?: string,
  parentId?: string,
  options?: { readonly limit?: number },
): Promise<{ rows: TenantChild[] }> {
  const params = new URLSearchParams();
  if (parentLevel) params.set('parentLevel', parentLevel);
  if (parentId) params.set('parentId', parentId);
  if (options?.limit !== undefined) params.set('limit', String(options.limit));
  const qs = params.toString();
  return apiRequest<{ rows: TenantChild[] }>(
    `/scope/children${qs ? `?${qs}` : ''}`,
  );
}
