"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNotificationSettings = getNotificationSettings;
exports.setNotificationSettings = setNotificationSettings;
exports.updateNotificationSettings = updateNotificationSettings;
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
const paths_1 = require("../server/paths");
function configDir() {
    return (0, paths_1.getCockpitDir)();
}
function configFile() {
    return (0, node_path_1.join)(configDir(), "notifications.json");
}
const fallback = {
    providers: [],
};
function getNotificationSettings() {
    try {
        return { ...fallback, ...JSON.parse((0, node_fs_1.readFileSync)(configFile(), "utf-8")) };
    }
    catch {
        return { ...fallback };
    }
}
function setNotificationSettings(settings) {
    try {
        (0, node_fs_1.mkdirSync)(configDir(), { recursive: true });
        (0, node_fs_1.writeFileSync)(configFile(), JSON.stringify(settings, null, 2) + "\n");
    }
    catch {
        // best effort
    }
    return settings;
}
function updateNotificationSettings(partial) {
    const current = getNotificationSettings();
    const updated = { ...current, ...partial };
    if (!(0, node_fs_1.existsSync)(configDir()))
        (0, node_fs_1.mkdirSync)(configDir(), { recursive: true });
    (0, node_fs_1.writeFileSync)(configFile(), JSON.stringify(updated, null, 2) + "\n");
    return updated;
}
