import { prisma } from "@/lib/db";
import { AGENT_LABEL, type AgentKind } from "@/lib/agents";
import AgentsListClient from "./list-client";

export const dynamic = "force-dynamic";

export default async function AgentsPage() {
  const agents = await prisma.agent.findMany({
    include: { host: true },
    orderBy: { createdAt: "desc" },
  });
  const rows = agents.map((a) => ({
    id: a.id,
    name: a.name,
    displayName: a.displayName,
    kind: AGENT_LABEL[a.kind as AgentKind],
    hostName: a.host.name,
    hostAddr: a.host.host,
    deployMethod: a.deployMethod,
    declared: a.declared,
    status: a.status,
    version: a.version,
    uptimeSec: a.uptimeSec ?? null,
    restartCount: a.restartCount ?? null,
    updatedAt: a.updatedAt.toISOString(),
  }));
  return <AgentsListClient initialRows={rows} />;
}
