// utils/blacklistUtil.js
const fs = require('fs');
const path = require('path');
const FILE = path.join(__dirname, '../blacklist.json');

function loadBlacklist() {
  try {
    if (!fs.existsSync(FILE)) return {};
    const raw = fs.readFileSync(FILE, 'utf8');
    const json = JSON.parse(raw || '{}');
    return typeof json === 'object' && json !== null ? json : {};
  } catch (e) {
    console.error('Failed to load blacklist.json', e.message);
    return {};
  }
}

function saveBlacklist(data) {
  try {
    fs.writeFileSync(FILE, JSON.stringify(data, null, 2), 'utf8');
  } catch (e) {
    console.error('Failed to save blacklist.json', e.message);
  }
}

module.exports = { loadBlacklist, saveBlacklist };
