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

const CATALOG_PATH = path.join(__dirname, 'catalog.json');

let cachedCatalog = null;

function loadActionCatalog(forceReload = false) {
  if (cachedCatalog && !forceReload) {
    return cachedCatalog;
  }

  const raw = fs.readFileSync(CATALOG_PATH, 'utf-8');
  cachedCatalog = JSON.parse(raw);
  return cachedCatalog;
}

function getAction(actionKey) {
  const catalog = loadActionCatalog();
  return catalog.actions ? catalog.actions[actionKey] : undefined;
}

module.exports = { loadActionCatalog, getAction };
