import { mkdirSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";

import { generateClient } from "./lib/generate-client.mjs";
import { buildApiContracts, createOpenApiDocument, formattedJson } from "./lib/openapi.mjs";

buildApiContracts();
const document = await createOpenApiDocument();
const snapshotPath = resolve("openapi/openapi.json");
mkdirSync(resolve("openapi"), { recursive: true });
writeFileSync(snapshotPath, formattedJson(document));
await generateClient(snapshotPath, resolve("apps/web/src/generated/api"));
console.log(JSON.stringify({ client: "generated", openapi: document.openapi, snapshot: "openapi/openapi.json" }));
