import fs from "node:fs";
import path from "node:path";

const root = process.cwd();
const outDir = path.join(root, "public", "__ops");
const outFile = path.join(outDir, "health.json");

const payload = {
  service: "archicratie-site",
  env: process.env.PUBLIC_OPS_ENV || "unknown",
  upstream: process.env.PUBLIC_OPS_UPSTREAM || "unknown",
  buildSha: process.env.PUBLIC_BUILD_SHA || "unknown",
  builtAt: process.env.PUBLIC_BUILD_TIME || new Date().toISOString(),
};

fs.mkdirSync(outDir, { recursive: true });
fs.writeFileSync(outFile, `${JSON.stringify(payload, null, 2)}\n`, "utf8");

console.log(`✅ ops health written: ${outFile}`);
console.log(payload);