/**
 * NBA team pace factors (Session 15).
 *
 * Source: NBA.com/stats team pace data 2024-25 season (possessions
 * per 48 minutes, league average ~98). Indexed to 100 = league
 * average so values compose multiplicatively with the player's
 * baseline stats — a 105-pace team adds ~5% to counting stats
 * (points, rebounds, assists, etc.); a 94-pace team subtracts ~6%.
 *
 * Update annually before the playoffs (the regular-season composite
 * is stable by All-Star break). For mid-season grades, consider
 * blending this static table with the live `team_pace` value the
 * orchestrator already computes from game logs.
 */

const PACE_FACTORS = Object.freeze({
  // East
  ATL: 103, BOS: 99,  BKN: 100, CHA: 102, CHI: 98,
  CLE: 96,  DET: 102, IND: 105, MIA: 98,  MIL: 99,
  NYK: 95,  ORL: 94,  PHI: 99,  TOR: 100, WAS: 102,
  // West
  DAL: 99,  DEN: 99,  GSW: 102, HOU: 102, LAC: 99,
  LAL: 100, MEM: 102, MIN: 99,  NOP: 100, OKC: 100,
  PHX: 99,  POR: 102, SAC: 104, SAS: 100, UTA: 102,
});

const LEAGUE_AVERAGE = 100;

function normalizeTeamCode(team) {
  if (!team) return null;
  return String(team).trim().toUpperCase();
}

/**
 * getPaceFactor — returns null for unknown teams so the feature
 * extractor drops the signal entirely rather than reporting "league-
 * average pace" on a typo.
 */
function getPaceFactor(team) {
  const code = normalizeTeamCode(team);
  if (!code) return null;
  // The grading orchestrator uses some legacy abbreviations:
  //   NJN → BKN (Nets relocated 2012)
  //   NOH/NOK → NOP (Pelicans rebrand)
  //   SEA → OKC (Sonics relocated)
  //   CHO → CHA (Hornets rebrand)
  // Folded here so old game-log teams still resolve to current pace.
  const alias = ALIASES[code];
  return PACE_FACTORS[alias || code] || null;
}

const ALIASES = Object.freeze({
  NJN: 'BKN',
  NOH: 'NOP',
  NOK: 'NOP',
  SEA: 'OKC',
  CHO: 'CHA',
});

module.exports = {
  PACE_FACTORS,
  LEAGUE_AVERAGE,
  ALIASES,
  getPaceFactor,
  __internals: { normalizeTeamCode },
};
