"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.paths = void 0;
const tslib_1 = require("tslib");
const path_1 = (0, tslib_1.__importDefault)(require("path"));
const os_1 = (0, tslib_1.__importDefault)(require("os"));
const process_1 = (0, tslib_1.__importDefault)(require("process"));
exports.paths = envPaths('io.refloat.agent', { suffix: '' });
const homedir = os_1.default.homedir();
const tmpdir = os_1.default.tmpdir();
const { env } = process_1.default;
function macos(name) {
    const library = path_1.default.join(homedir, 'Library');
    return {
        data: path_1.default.join(library, 'Application Support', name),
        config: path_1.default.join(library, 'Preferences', name),
        cache: path_1.default.join(library, 'Caches', name),
        log: path_1.default.join(library, 'Logs', name),
        temp: path_1.default.join(tmpdir, name),
    };
}
function windows(name) {
    const appData = env.APPDATA || path_1.default.join(homedir, 'AppData', 'Roaming');
    const localAppData = env.LOCALAPPDATA || path_1.default.join(homedir, 'AppData', 'Local');
    return {
        // Data/config/cache/log are invented by me as Windows isn't opinionated about this
        data: path_1.default.join(localAppData, name, 'Data'),
        config: path_1.default.join(appData, name, 'Config'),
        cache: path_1.default.join(localAppData, name, 'Cache'),
        log: path_1.default.join(localAppData, name, 'Log'),
        temp: path_1.default.join(tmpdir, name),
    };
}
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
function linux(name) {
    const username = path_1.default.basename(homedir);
    return {
        data: path_1.default.join(env.XDG_DATA_HOME || path_1.default.join(homedir, '.local', 'share'), name),
        config: path_1.default.join(env.XDG_CONFIG_HOME || path_1.default.join(homedir, '.config'), name),
        cache: path_1.default.join(env.XDG_CACHE_HOME || path_1.default.join(homedir, '.cache'), name),
        // https://wiki.debian.org/XDGBaseDirectorySpecification#state
        log: path_1.default.join(env.XDG_STATE_HOME || path_1.default.join(homedir, '.local', 'state'), name),
        temp: path_1.default.join(tmpdir, username, name),
    };
}
function envPaths(name, { suffix = 'nodejs' } = {}) {
    if (typeof name !== 'string') {
        throw new TypeError(`Expected a string, got ${typeof name}`);
    }
    if (suffix) {
        // Add suffix to prevent possible conflict with native apps
        name += `-${suffix}`;
    }
    if (process_1.default.platform === 'darwin') {
        return macos(name);
    }
    if (process_1.default.platform === 'win32') {
        return windows(name);
    }
    return linux(name);
}
//# sourceMappingURL=paths.js.map