import {
	readSwarmDashboardRows,
	SWARMS_REGISTRY_PATH,
} from "@/lib/swarm-status";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";

export async function GET(): Promise<Response> {
	const swarms = readSwarmDashboardRows();
	const summary = {
		total: swarms.length,
		ok: swarms.filter((swarm) => swarm.status === "ok").length,
		degraded: swarms.filter((swarm) => swarm.status === "degraded").length,
		missing: swarms.filter((swarm) => swarm.status === "missing").length,
	};
	return Response.json(
		{
			schemaVersion: 1,
			registryPath: SWARMS_REGISTRY_PATH,
			summary,
			swarms,
		},
		{
			headers: {
				"Cache-Control": "no-store",
			},
		},
	);
}
