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

const FILE = path.join(__dirname, "../../token.json");

function saveTokenData(data) {
  fs.writeFileSync(FILE, JSON.stringify(data, null, 2));
}

function loadTokenData() {
  if (!fs.existsSync(FILE)) return null;

  try {
    return JSON.parse(fs.readFileSync(FILE, "utf-8"));
  } catch (e) {
    return null;
  }
}

module.exports = {
  saveTokenData,
  loadTokenData,
};