"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_os_1 = require("node:os");
const node_path_1 = require("node:path");
const CONFIG_DIR = (0, node_path_1.join)((0, node_os_1.homedir)(), ".cockpit");
const CONFIG_FILE = (0, node_path_1.join)(CONFIG_DIR, "notifications.json");
const fallback = {
    providers: [],
};
function getNotificationSettings() {
    try {
        return { ...fallback, ...JSON.parse((0, node_fs_1.readFileSync)(CONFIG_FILE, "utf-8")) };
    }
    catch {
        return { ...fallback };
    }
}
function setNotificationSettings(settings) {
    try {
        (0, node_fs_1.mkdirSync)(CONFIG_DIR, { recursive: true });
        (0, node_fs_1.writeFileSync)(CONFIG_FILE, 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)(CONFIG_DIR))
        (0, node_fs_1.mkdirSync)(CONFIG_DIR, { recursive: true });
    (0, node_fs_1.writeFileSync)(CONFIG_FILE, JSON.stringify(updated, null, 2) + "\n");
    return updated;
}
