import dotenv from "dotenv";
import path from "path";
import { fileURLToPath } from "url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.join(__dirname, "..", "..", "..");

/**
 * Load JWT/DB env shared with SAT and ORAC (same order as combined-server.mjs).
 * SWI-local `.env` overrides when present.
 */
export function loadSwiEnv() {
  dotenv.config({ path: path.join(repoRoot, ".env") });
  dotenv.config({ path: path.join(repoRoot, "SAT_backend", ".env") });
  dotenv.config({
    path: path.join(repoRoot, "Risk_assessment_backend", ".env"),
  });
  dotenv.config({ path: path.join(__dirname, "..", "..", ".env") });
}
