const DEFAULT_ELO = 800;
const BASE_CHANGE = 10;
const DIFF_STEP   = 30;
const MAX_CHANGE  = 30;
const MIN_CHANGE  = 1;

// Calculate ELO change for a completed match.
// Magnitude is derived once from the winner's perspective so both sides
// move by the same amount (winner gains X, loser loses X).
function calculateElo(winnerElo, loserElo) {
  const diff      = loserElo - winnerElo; // positive = underdog won, negative = favourite won
  const magnitude = Math.max(MIN_CHANGE, Math.min(MAX_CHANGE, BASE_CHANGE + Math.floor(diff / DIFF_STEP)));
  return { winnerChange: magnitude, loserChange: -magnitude };
}

module.exports = { calculateElo, DEFAULT_ELO };
