/**
 * Venue coordinates + dome flags (Session 15).
 *
 * Sources:
 *   - MLB stadium coordinates: Wikipedia infoboxes, cross-checked against
 *     each team's "stadium" entry on baseball-reference.com (2025).
 *   - World Cup 2026 venues: official FIFA host-city announcements + the
 *     static venue list already in `src/data/worldcup2026.js`.
 *   - Dome flag = roof either fully closed or retractable. Retractable
 *     stadiums count as dome for weather purposes (operators close the
 *     roof when conditions warrant — weather doesn't drive grade).
 *
 * Lat/lon precision: 4 decimal places (~10m). Sufficient for an
 * Open-Meteo grid-cell lookup. Higher precision would be theater.
 */

// ---- MLB ----

const MLB_VENUES = Object.freeze({
  // AL East
  BAL: { lat: 39.2839, lon: -76.6217, dome: false, name: 'Camden Yards' },
  BOS: { lat: 42.3467, lon: -71.0972, dome: false, name: 'Fenway Park' },
  NYY: { lat: 40.8296, lon: -73.9262, dome: false, name: 'Yankee Stadium' },
  TB:  { lat: 27.7682, lon: -82.6534, dome: true,  name: 'Tropicana Field' },
  TOR: { lat: 43.6414, lon: -79.3894, dome: true,  name: 'Rogers Centre' },
  // AL Central
  CHW: { lat: 41.8300, lon: -87.6338, dome: false, name: 'Guaranteed Rate Field' },
  CLE: { lat: 41.4962, lon: -81.6852, dome: false, name: 'Progressive Field' },
  DET: { lat: 42.3390, lon: -83.0485, dome: false, name: 'Comerica Park' },
  KC:  { lat: 39.0517, lon: -94.4803, dome: false, name: 'Kauffman Stadium' },
  MIN: { lat: 44.9817, lon: -93.2778, dome: false, name: 'Target Field' },
  // AL West
  HOU: { lat: 29.7572, lon: -95.3553, dome: true,  name: 'Minute Maid Park' },
  LAA: { lat: 33.8003, lon: -117.8827, dome: false, name: 'Angel Stadium' },
  OAK: { lat: 37.7516, lon: -122.2005, dome: false, name: 'Oakland Coliseum' },
  SEA: { lat: 47.5914, lon: -122.3324, dome: true,  name: 'T-Mobile Park' }, // retractable
  TEX: { lat: 32.7475, lon: -97.0822, dome: true,  name: 'Globe Life Field' }, // retractable
  // NL East
  ATL: { lat: 33.8908, lon: -84.4678, dome: false, name: 'Truist Park' },
  MIA: { lat: 25.7781, lon: -80.2197, dome: true,  name: 'loanDepot park' }, // retractable
  NYM: { lat: 40.7571, lon: -73.8458, dome: false, name: 'Citi Field' },
  PHI: { lat: 39.9061, lon: -75.1665, dome: false, name: 'Citizens Bank Park' },
  WSH: { lat: 38.8730, lon: -77.0074, dome: false, name: 'Nationals Park' },
  // NL Central
  CHC: { lat: 41.9484, lon: -87.6553, dome: false, name: 'Wrigley Field' },
  CIN: { lat: 39.0975, lon: -84.5067, dome: false, name: 'Great American Ball Park' },
  MIL: { lat: 43.0280, lon: -87.9712, dome: true,  name: 'American Family Field' }, // retractable
  PIT: { lat: 40.4469, lon: -80.0058, dome: false, name: 'PNC Park' },
  STL: { lat: 38.6226, lon: -90.1928, dome: false, name: 'Busch Stadium' },
  // NL West
  ARI: { lat: 33.4453, lon: -112.0667, dome: true,  name: 'Chase Field' }, // retractable
  COL: { lat: 39.7559, lon: -104.9942, dome: false, name: 'Coors Field' },
  LAD: { lat: 34.0739, lon: -118.2400, dome: false, name: 'Dodger Stadium' },
  SD:  { lat: 32.7073, lon: -117.1566, dome: false, name: 'Petco Park' },
  SF:  { lat: 37.7786, lon: -122.3893, dome: false, name: 'Oracle Park' },
});

function normalizeCode(code) {
  if (!code) return null;
  return String(code).trim().toUpperCase();
}

function getMlbVenue(teamCode) {
  const code = normalizeCode(teamCode);
  if (!code) return null;
  return MLB_VENUES[code] || null;
}

// ---- World Cup 2026 ----
// Sourced from src/data/worldcup2026.js (the canonical list of host
// venues + altitudes). Added lat/lon + dome flag here to keep the
// weather-fetch path independent of the i18n/altitude consumer.
const WC_VENUES = Object.freeze({
  'MetLife Stadium':         { lat: 40.8135, lon: -74.0746, dome: false },
  'AT&T Stadium':            { lat: 32.7473, lon: -97.0945, dome: true  }, // retractable
  'SoFi Stadium':            { lat: 33.9535, lon: -118.3392, dome: true }, // partial roof
  'Hard Rock Stadium':       { lat: 25.9580, lon: -80.2389, dome: false },
  'Lincoln Financial Field': { lat: 39.9008, lon: -75.1675, dome: false },
  'Lumen Field':             { lat: 47.5952, lon: -122.3316, dome: false },
  'Gillette Stadium':        { lat: 42.0909, lon: -71.2643, dome: false },
  'Mercedes-Benz Stadium':   { lat: 33.7553, lon: -84.4006, dome: true  }, // retractable
  'NRG Stadium':             { lat: 29.6847, lon: -95.4107, dome: true  }, // retractable
  'Arrowhead Stadium':       { lat: 39.0489, lon: -94.4839, dome: false },
  'BC Place':                { lat: 49.2768, lon: -123.1116, dome: true }, // retractable
  'BMO Field':               { lat: 43.6332, lon: -79.4185, dome: false },
  'Estadio Azteca':          { lat: 19.3030, lon: -99.1503, dome: false },
  'Estadio BBVA':            { lat: 25.6692, lon: -100.2444, dome: false },
  'Estadio Akron':           { lat: 20.6817, lon: -103.4625, dome: false },
  "Levi's Stadium":          { lat: 37.4032, lon: -121.9698, dome: false },
});

function getWcVenueCoords(name) {
  if (!name) return null;
  return WC_VENUES[name] || null;
}

module.exports = {
  MLB_VENUES,
  WC_VENUES,
  getMlbVenue,
  getWcVenueCoords,
  __internals: { normalizeCode },
};
