// Thin client over the live Vaultfire API.

import { VAULTFIRE_API } from './vaultfire';

export interface AgentStatus {
  registered: boolean;
  address: string;
  chain: string;
  vnsName?: string;
  name?: string;
  description?: string;
  identityType?: string;
  capabilities?: string[];
  active?: boolean;
  registeredAt?: number;
}

export async function getAgentStatus(
  address: string,
  chain: 'base' = 'base'
): Promise<AgentStatus> {
  const r = await fetch(
    `${VAULTFIRE_API}/api/agent/status?address=${address}&chain=${chain}`,
    { cache: 'no-store' }
  );
  if (!r.ok) throw new Error(`status ${r.status}`);
  return r.json();
}

export interface HubStats {
  totalAgents?: number;
  totalBonds?: number;
  totalContracts?: number;
  chains?: Record<string, { agents: number; bonds?: number }>;
}

export async function getHubStats(): Promise<HubStats> {
  const r = await fetch(`${VAULTFIRE_API}/api/hub/stats`, {
    cache: 'no-store',
  });
  if (!r.ok) throw new Error(`stats ${r.status}`);
  return r.json();
}
