import { readFileSync } from "node:fs";
let cached = null;
export function getConfig() {
    if (cached)
        return cached;
    const databaseUrl = process.env.NOTIFY_DATABASE_URL;
    if (!databaseUrl)
        throw new Error("NOTIFY_DATABASE_URL is not set");
    cached = {
        databaseUrl,
        fcm: loadFcm(),
    };
    return cached;
}
function loadFcm() {
    const projectId = process.env.NOTIFY_FCM_PROJECT_ID;
    const keyPath = process.env.NOTIFY_FCM_SERVICE_ACCOUNT;
    if (!projectId && !keyPath)
        return null;
    if (!projectId || !keyPath) {
        throw new Error("Set both NOTIFY_FCM_PROJECT_ID and NOTIFY_FCM_SERVICE_ACCOUNT, or neither");
    }
    const parsed = JSON.parse(readFileSync(keyPath, "utf8"));
    if (!parsed.client_email || !parsed.private_key) {
        throw new Error("NOTIFY_FCM_SERVICE_ACCOUNT is not a service-account key file");
    }
    return { projectId, clientEmail: parsed.client_email, privateKeyPem: parsed.private_key };
}
