"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileCredentialStore = void 0;
const node_fs_1 = require("node:fs");
const node_path_1 = __importDefault(require("node:path"));
class FileCredentialStore {
    filePath;
    constructor(storageDir) {
        this.filePath = node_path_1.default.join(storageDir, "admin-session.json");
    }
    async load() {
        try {
            const content = await node_fs_1.promises.readFile(this.filePath, "utf8");
            return JSON.parse(content);
        }
        catch (error) {
            if (error.code === "ENOENT")
                return null;
            throw error;
        }
    }
    async save(session) {
        await node_fs_1.promises.mkdir(node_path_1.default.dirname(this.filePath), { recursive: true, mode: 0o700 });
        await node_fs_1.promises.writeFile(this.filePath, JSON.stringify(session, null, 2), { mode: 0o600 });
    }
}
exports.FileCredentialStore = FileCredentialStore;
