"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSessionToken = getSessionToken;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const os_1 = __importDefault(require("os"));
let sessionToken = null;
const crypto_1 = __importDefault(require("crypto"));
function getSessionToken() {
    if (!sessionToken) {
        const tokenFile = path_1.default.join(os_1.default.homedir(), '.nyxora', 'auth.token');
        try {
            if (fs_1.default.existsSync(tokenFile)) {
                sessionToken = fs_1.default.readFileSync(tokenFile, 'utf8').trim();
            }
            else {
                sessionToken = crypto_1.default.randomBytes(32).toString('hex');
                fs_1.default.writeFileSync(tokenFile, sessionToken, { mode: 0o600 });
            }
        }
        catch (e) {
            if (!sessionToken)
                sessionToken = crypto_1.default.randomBytes(32).toString('hex');
        }
    }
    return sessionToken;
}
