const API_BASE = '/api/kcg';

export interface CollectorInfo {
  name: string;
  region: string;
  lastSuccess: string;
  lastFailure: string;
  lastCount: number;
  lastError: string;
  totalSuccess: number;
  totalFailure: number;
  totalItems: number;
}

interface CollectorStatusResponse {
  collectors: CollectorInfo[];
  serverTime: string;
}

export async function fetchCollectorStatus(): Promise<CollectorStatusResponse> {
  const res = await fetch(`${API_BASE}/admin/collector-status`, {
    headers: { Accept: 'application/json' },
  });
  if (!res.ok) throw new Error(`collector-status ${res.status}`);
  return res.json() as Promise<CollectorStatusResponse>;
}
