const os = require("os");
const path = require("path");
const fs = require("fs");

function configureAppDataPaths(app, dataId, homeDirectory = os.homedir()) {
    const dataPath = path.join(
        homeDirectory,
        ".local",
        "share",
        "swai",
        "app_data",
        dataId,
    );

    const paths = {
        userData: path.join(dataPath, "userData"),
        appData: path.join(dataPath, "appData"),
        sessionData: path.join(dataPath, "sessionData"),
        cache: path.join(dataPath, "cache"),
        logs: path.join(dataPath, "logs"),
        crashDumps: path.join(dataPath, "crashDumps"),
    };

    for (const [name, value] of Object.entries(paths)) {
        fs.mkdirSync(value, { recursive: true });
        app.setPath(name, value);
    }

    return paths;
}

module.exports = { configureAppDataPaths };
