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

const rewards = new Map();

function loadRewards() {
  const files = fs.readdirSync(__dirname);

  for (const file of files) {
    if (file === "index.js") continue;
    if (!file.endsWith(".js")) continue;

    const reward = require(path.join(__dirname, file));

    if (!reward.name || !reward.run) {
      console.warn(`⚠️ Invalid reward file: ${file}`);
      continue;
    }

    rewards.set(reward.name.toLowerCase(), reward.run);
    console.log(`📦 Loaded reward: ${reward.name}`);
  }
}

function getReward(name) {
  return rewards.get(name.toLowerCase());
}

module.exports = { loadRewards, getReward };