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

const MAPPINGS_FILE = path.join(__dirname, '../../role-mappings.json');

function getRoleMappings() {
  try {
    if (!fs.existsSync(MAPPINGS_FILE)) {
      return {};
    }
    const data = fs.readFileSync(MAPPINGS_FILE, 'utf8');
    return JSON.parse(data);
  } catch (error) {
    console.error('Error reading role mappings:', error);
    return {};
  }
}

function saveRoleMappings(mappings) {
  try {
    fs.writeFileSync(MAPPINGS_FILE, JSON.stringify(mappings, null, 2));
    return true;
  } catch (error) {
    console.error('Error saving role mappings:', error);
    return false;
  }
}

module.exports = { getRoleMappings, saveRoleMappings };
