import { writeFile } from "node:fs/promises";
import { isSnapshotSet } from "../lib/liquidity-set.ts";
import { SITE_URL } from "../lib/site-config.ts";
const response = await fetch(`${SITE_URL}/api/liquidity`, { signal: AbortSignal.timeout(20_000) });
if (!response.ok) throw new Error(`Snapshot API: HTTP ${response.status}`);
const data = await response.json();
if (!isSnapshotSet(data.chains)) throw new Error("Expected a complete set of all three chains");
for (const [chain, payload] of Object.entries(data.chains)) {
  const filename = chain === "robinhood" ? "liquidity-snapshot.json" : `liquidity-snapshot-${chain}.json`;
  await writeFile(new URL(`../lib/${filename}`, import.meta.url), JSON.stringify(payload, null, 2) + "\n");
}
await writeFile(new URL("../public/data/latest.json", import.meta.url), JSON.stringify(data, null, 2) + "\n");
console.log("Saved all three complete snapshots, preserving their actual observation times.");
