import { canonicalTeam } from '../teams';

// Host advantage: the three host nations get a home boost when they play in a
// venue in their own country. Everyone else plays on neutral ground.

const VENUE_COUNTRY: Record<string, string> = {
  'Mexico City': 'Mexico',
  'Guadalajara (Zapopan)': 'Mexico',
  'Monterrey (Guadalupe)': 'Mexico',
  Toronto: 'Canada',
  Vancouver: 'Canada',
  // everything else is in the USA
};
const HOST_TEAM: Record<string, string> = { Mexico: 'Mexico', Canada: 'Canada', USA: 'USA' };

function venueCountry(venue: string): string {
  return VENUE_COUNTRY[venue] ?? 'USA';
}

/**
 * Elo home-advantage to apply to the *home* slot for a fixture. Positive if the
 * nominal home team is the host playing at home; negative if the away team is;
 * zero otherwise (neutral). Pass the result straight into lambdasFromElo.
 */
export function hostAdvantage(home: string, away: string, venue: string, homeAdvElo: number): number {
  const host = HOST_TEAM[venueCountry(venue)];
  if (!host) return 0;
  if (canonicalTeam(home) === host) return homeAdvElo;
  if (canonicalTeam(away) === host) return -homeAdvElo;
  return 0;
}
