const TIERS = ["HT1", "LT1", "HT2", "LT2", "HT3", "LT3", "HT4", "LT4", "HT5", "LT5"];

const TIER_POINTS = {
  HT1: 60,
  LT1: 45,
  HT2: 30,
  LT2: 20,
  HT3: 10,
  LT3: 6,
  HT4: 4,
  LT4: 3,
  HT5: 2,
  LT5: 1,
};

const GAMEMODES = [
  "vanilla",
  "mace",
  "axe",
  "sword",
  "smp",
  "diamondsmp",
  "uhc",
  "pot",
  "nethop",
  "cart",
];

const GAMEMODE_LABELS = {
  vanilla: "Vanilla",
  mace: "Mace",
  axe: "Axe",
  sword: "Sword",
  smp: "SMP",
  diamondsmp: "Diamond SMP",
  uhc: "UHC",
  pot: "Pot",
  nethop: "Neth OP",
  cart: "Cart",
};

const USERNAME_REGEX = /^[A-Za-z0-9_]{3,16}$/;
const REGIONS = ["NA", "EU", "AS", "AU"];

function avatarUrl(username) {
  return `https://render.crafty.gg/3d/bust/${encodeURIComponent(username)}`;
}

function isValidTier(tier) {
  return TIERS.includes(String(tier || "").toUpperCase());
}

function isValidGamemode(gamemode) {
  return GAMEMODES.includes(String(gamemode || "").toLowerCase());
}

function normalizeTier(tier) {
  return String(tier || "").toUpperCase();
}

function normalizeGamemode(gamemode) {
  return String(gamemode || "").toLowerCase();
}

function tierToPoints(tier) {
  return TIER_POINTS[tier] || 0;
}

function isValidRegion(region) {
  return REGIONS.includes(String(region || "").toUpperCase());
}

function normalizeRegion(region) {
  return String(region || "").toUpperCase();
}

module.exports = {
  TIERS,
  TIER_POINTS,
  GAMEMODES,
  GAMEMODE_LABELS,
  USERNAME_REGEX,
  REGIONS,
  avatarUrl,
  isValidTier,
  isValidGamemode,
  isValidRegion,
  normalizeTier,
  normalizeGamemode,
  normalizeRegion,
  tierToPoints,
};
