"""
Bootstrap historical economic calendar events into market_events DB.
Covers 2020-2026 with actual vs expected values and surprise metrics.
Categories: FOMC, NFP, CPI, GDP, ISM/PMI, BOJ, ECB, BOE.
Convention: surprise_pct positive = bullish surprise, negative = bearish.
"""
import logging
from typing import List, Dict, Any

logger = logging.getLogger(__name__)

# Shared asset groups
_EQ    = ["SPY", "QQQ", "IWM"]
_RATES = ["TLT", "HYG"]
_FX    = ["EURUSD=X", "USDJPY=X", "GBPUSD=X"]
_SAFE  = ["GLD", "VXX"]
_ALL   = _EQ + _RATES + ["EURUSD=X", "GLD", "BTC-USD"]

ECO_EVENTS: List[Dict[str, Any]] = [

    # ══════════════════════════════════════════════════════════
    # FOMC — DECISIONS DE TAUX (2020-2025)
    # ══════════════════════════════════════════════════════════

    {"name": "FOMC — Urgence COVID : coupe -50pb (entre-séances)",
     "start_date": "2020-03-03", "level": "long", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "-25pb", "actual_value": "-50pb", "surprise_pct": -12,
     "unit": "pb", "impact_score": 0.95, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "Fed coupe -50pb en urgence hors-séance (premier depuis 2008). COVID commence à impacter les marchés. S&P500 avait perdu -10% en une semaine. Marché attendait -25pb."},

    {"name": "FOMC — Urgence COVID : taux à 0% + QE illimité",
     "start_date": "2020-03-16", "level": "long", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "-50pb", "actual_value": "-100pb + QE∞", "surprise_pct": -20,
     "unit": "pb", "impact_score": 0.98, "absorption_pct": 100,
     "affected_assets": _ALL + ["USO", "EEM"],
     "description": "FOMC coupe -100pb en urgence, amène taux à 0-0.25%. Lance QE illimité (Treasuries + MBS). Bazooka monétaire COVID. Circuit breakers activés ce matin. Le tout en un seul dimanche soir."},

    {"name": "FOMC — Taper talk (dot plot hawkish inattendu)",
     "start_date": "2021-06-16", "level": "medium", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "stable", "actual_value": "2 hausses en 2023 signalées", "surprise_pct": -18,
     "unit": "signal", "impact_score": 0.82, "absorption_pct": 100,
     "affected_assets": _EQ + _RATES + ["GLD", "EURUSD=X"],
     "description": "Dot plot de juin 2021 révèle que 13 des 18 membres FOMC prévoient 2+ hausses d'ici 2023. Surprise hawkish. Gold -5% en 2 jours. DXY +1%. Prémices du pivot narratif 2022."},

    {"name": "FOMC — Début réduction QE (tapering annoncé)",
     "start_date": "2021-11-03", "level": "medium", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "taper annoncé", "actual_value": "$15Md/mois taper", "surprise_pct": 0,
     "unit": "signal", "impact_score": 0.78, "absorption_pct": 100,
     "affected_assets": _EQ + _RATES + ["GLD", "EURUSD=X"],
     "description": "Fed annonce début du tapering à -$15Md/mois (Nov-Déc 2021). Largement attendu. Marché absorbe sans choc majeur. SPY au plus haut. Signale la fin de l'ère QE COVID."},

    {"name": "FOMC — Accélération taper + 3 hausses 2022 signalées",
     "start_date": "2021-12-15", "level": "long", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "taper accéléré", "actual_value": "-$30Md/mois + 3 hausses 2022", "surprise_pct": -15,
     "unit": "signal", "impact_score": 0.85, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "Fed double la vitesse du tapering (-$30Md/mois) et signale 3 hausses en 2022 vs 1 attendue. Inflation à 6.8% force Powell à pivoter hawkish. Dollar se renforce. Gold résiste."},

    {"name": "FOMC — Premier hike cycle : +25pb (premier depuis 2018)",
     "start_date": "2022-03-16", "level": "long", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "+25pb", "actual_value": "+25pb (cibles 0.25-0.50%)", "surprise_pct": 0,
     "unit": "pb", "impact_score": 0.88, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "Premier hike depuis déc 2018. Taux cible 0.25-0.50%. Ukraine envahie 3 semaines avant. Dot plot : 7 hausses totales en 2022. Powell dit 'l'économie est forte'. Début du cycle de resserrement le plus agressif depuis 40 ans."},

    {"name": "FOMC — +50pb (premier double hike depuis 2000)",
     "start_date": "2022-05-04", "level": "medium", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "+50pb", "actual_value": "+50pb + QT annoncé", "surprise_pct": -5,
     "unit": "pb", "impact_score": 0.82, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "+50pb, plus forte hausse depuis 2000. Taux 0.75-1.00%. Annonce début QT en juin (-$95Md/mois). CPI à 8.3%. Conférence de presse : Powell exclut +75pb pour la prochaine réunion (retournement de veste en juin)."},

    {"name": "FOMC — Choc +75pb : surprise hawkish (attendu +50pb)",
     "start_date": "2022-06-15", "level": "long", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "+50pb", "actual_value": "+75pb", "surprise_pct": -25,
     "unit": "pb", "impact_score": 0.96, "absorption_pct": 100,
     "affected_assets": _ALL + ["EEM", "USO"],
     "description": "Fed remonte +75pb, plus fort depuis 1994. FOMC dit +50pb en mai, mais CPI jun 9.1% force la main. Dot plot : taux terminal à 3.4% fin 2022. SPY -3.5%, TLT -2%. Début du bear market officiel."},

    {"name": "FOMC — +75pb (2e consécutif)",
     "start_date": "2022-07-27", "level": "medium", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "+75pb", "actual_value": "+75pb (taux 2.25-2.50%)", "surprise_pct": 0,
     "unit": "pb", "impact_score": 0.82, "absorption_pct": 100,
     "affected_assets": _EQ + _RATES + ["GLD", "EURUSD=X"],
     "description": "2e +75pb consécutif. Taux 2.25-2.50%. Powell dit 'probablement approprié de ralentir'. Marché interprète comme dovish → rally court terme. GDP Q2 -0.9% annoncé le même jour (récession technique)."},

    {"name": "FOMC — +75pb + dot plot terminal 4.6% (hawkish peak)",
     "start_date": "2022-09-21", "level": "long", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "+75pb", "actual_value": "+75pb + terminal 4.6%", "surprise_pct": -20,
     "unit": "pb", "impact_score": 0.93, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "3e +75pb. Dot plot choque le marché: taux terminal révisé à 4.6% pour 2023. 'Higher for longer' officiel. Dollar index au plus haut 20 ans. SPY perd -5% semaine. Tous les actifs se vendent."},

    {"name": "FOMC — +75pb (4e consécutif)",
     "start_date": "2022-11-02", "level": "medium", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "+75pb", "actual_value": "+75pb (taux 3.75-4.00%)", "surprise_pct": 0,
     "unit": "pb", "impact_score": 0.85, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "4e +75pb consécutif. Mais communication laisse entrevoir un ralentissement à venir. 'Timing et ampleur des hausses futures' → signal de pivot. Marché commence à pricer pivot 2023."},

    {"name": "FOMC — Décélération +50pb (fin des gros moves)",
     "start_date": "2022-12-14", "level": "medium", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "+50pb", "actual_value": "+50pb + terminal 5.1%", "surprise_pct": -8,
     "unit": "pb", "impact_score": 0.80, "absorption_pct": 100,
     "affected_assets": _EQ + _RATES + ["GLD", "EURUSD=X"],
     "description": "Décélération à +50pb mais dot plot hawkish : terminal révisé à 5.1% (vs 4.6% en sept). SPY -2.5% sur la semaine. Marché était trop optimiste sur le pivot. Gold résistant."},

    {"name": "FOMC — +25pb (déceleration confirmée)",
     "start_date": "2023-02-01", "level": "medium", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "+25pb", "actual_value": "+25pb (taux 4.50-4.75%)", "surprise_pct": +5,
     "unit": "pb", "impact_score": 0.75, "absorption_pct": 100,
     "affected_assets": _EQ + _RATES + ["GLD", "EURUSD=X"],
     "description": "Premier +25pb depuis mars 2022. Powell signale 'quelques hausses supplémentaires'. Ton moins hawkish qu'attendu. SPY +1.5%. BTC rally. Début du discours désinflation 2023."},

    {"name": "FOMC — +25pb (avant crise SVB)",
     "start_date": "2023-03-22", "level": "medium", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "+25pb", "actual_value": "+25pb + doutes sur la suite", "surprise_pct": +5,
     "unit": "pb", "impact_score": 0.78, "absorption_pct": 100,
     "affected_assets": _EQ + _RATES + ["GLD", "EURUSD=X", "HYG"],
     "description": "Réunion post-SVB (faillite 10 mars). Powell dit la crise bancaire remplace 'une ou deux hausses' de taux. Signal de pause proche. Taux 4.75-5.00%. GLD fort sur les craintes bancaires."},

    {"name": "FOMC — Dernière hausse du cycle : +25pb",
     "start_date": "2023-05-03", "level": "long", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "+25pb", "actual_value": "+25pb (taux 5.00-5.25%)", "surprise_pct": 0,
     "unit": "pb", "impact_score": 0.82, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "Dernière hausse du cycle de resserrement. Taux au plus haut depuis 2007 : 5.00-5.25%. Powell retire la phrase 'additional firming may be appropriate'. Signal de pause officieux. Marché voit le pic."},

    {"name": "FOMC — Première pause du cycle (skip)",
     "start_date": "2023-06-14", "level": "long", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "+25pb ou pause", "actual_value": "pause (hold)", "surprise_pct": +8,
     "unit": "signal", "impact_score": 0.80, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "Première pause depuis mars 2022. Taux stable à 5.00-5.25%. Mais dot plot révise à 5.6% le terminal : une hausse de plus attendue en 2023. SPY tient les gains. 'Higher for longer' s'installe."},

    {"name": "FOMC — Pivot historique : première baisse -50pb (surprise)",
     "start_date": "2024-09-18", "level": "long", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "-25pb", "actual_value": "-50pb", "surprise_pct": +20,
     "unit": "pb", "impact_score": 0.94, "absorption_pct": 100,
     "affected_assets": _ALL + ["EEM", "USO"],
     "description": "Premier cut depuis mars 2020. La Fed surprend avec -50pb alors que le consensus était -25pb. Taux 4.75-5.00%. Powell: 'Cette décision témoigne de notre confiance croissante'. SPY +1%, GLD +1.2%, BTC +3%. Début du cycle d'assouplissement 2024."},

    {"name": "FOMC — Deuxième baisse -25pb du cycle",
     "start_date": "2024-11-07", "level": "medium", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "-25pb", "actual_value": "-25pb (taux 4.50-4.75%)", "surprise_pct": 0,
     "unit": "pb", "impact_score": 0.72, "absorption_pct": 100,
     "affected_assets": _EQ + _RATES + ["GLD", "EURUSD=X"],
     "description": "2e coupe du cycle. Lendemain des élections Trump → incertitude tarifaire. Fed ignore les résultats d'élection. Taux 4.50-4.75%. Marché commence à se questionner sur 2025."},

    {"name": "FOMC — Dot plot hawkish : 2 cuts 2025 seulement",
     "start_date": "2024-12-18", "level": "long", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "-25pb + 4 cuts 2025", "actual_value": "-25pb + 2 cuts 2025", "surprise_pct": -18,
     "unit": "pb", "impact_score": 0.87, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "3e coupe mais dot plot choc : révision de 4 à 2 baisses prévues en 2025. 'Higher for longer' resurgit. SPY -3% sur la séance. TLT -1.5%. Dollar index au plus haut annuel. Correction de fin d'année violente."},

    {"name": "FOMC — Hold (incertitude tarifs Trump)",
     "start_date": "2025-01-29", "level": "medium", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "hold", "actual_value": "hold (taux 4.25-4.50%)", "surprise_pct": 0,
     "unit": "pb", "impact_score": 0.70, "absorption_pct": 100,
     "affected_assets": _EQ + _RATES + ["GLD", "EURUSD=X"],
     "description": "Première réunion de l'ère Trump 2. Fed en pause. Incertitude tarifaire force la prudence. CPI encore au-dessus de 2%. Marché commence à réviser les anticipations de baisses 2025 à la baisse."},

    {"name": "FOMC — Hold (choc tarifaire Liberation Day)",
     "start_date": "2025-05-07", "level": "medium", "category": "event_calendar", "sub_type": "FOMC",
     "expected_value": "hold", "actual_value": "hold — 'wait and see' tarifaire", "surprise_pct": 0,
     "unit": "pb", "impact_score": 0.72, "absorption_pct": 100,
     "affected_assets": _EQ + _RATES + ["GLD", "EURUSD=X"],
     "description": "Fed en mode attentiste post Liberation Day (tarifs réciproques Trump). Stagflation imminente : inflation tarifaire vs ralentissement croissance. Marché incertain sur timing prochain move."},

    # ══════════════════════════════════════════════════════════
    # NFP — NON-FARM PAYROLLS (2020-2025)
    # ══════════════════════════════════════════════════════════

    {"name": "NFP Mars 2020 — Premier choc COVID (-701K)",
     "start_date": "2020-04-03", "level": "medium", "category": "event_calendar", "sub_type": "NFP",
     "expected_value": "-100K", "actual_value": "-701K", "surprise_pct": -85,
     "unit": "K emplois", "impact_score": 0.88, "absorption_pct": 100,
     "affected_assets": _EQ + ["GLD", "TLT", "VXX"],
     "description": "NFP mars 2020 : -701K (premier mois plein COVID). Attendu -100K. Début de la destruction d'emplois. Le pire viendra en avril. Chômage : 4.4% vs 3.5% en février."},

    {"name": "NFP Avril 2020 — Record absolu destruction emplois (-20.5M)",
     "start_date": "2020-05-08", "level": "long", "category": "event_calendar", "sub_type": "NFP",
     "expected_value": "-22000K", "actual_value": "-20537K", "surprise_pct": +8,
     "unit": "K emplois", "impact_score": 0.98, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "NFP avril 2020 : -20.537M emplois détruits en un seul mois. Record absolu dans l'histoire moderne. Chômage 14.7%. Légèrement mieux qu'attendu (-22M) = paradoxal rallye. Début du V-shape recovery."},

    {"name": "NFP Mai 2020 — Surprise massive de reprise (+2.5M)",
     "start_date": "2020-06-05", "level": "long", "category": "event_calendar", "sub_type": "NFP",
     "expected_value": "-8000K", "actual_value": "+2509K", "surprise_pct": +100,
     "unit": "K emplois", "impact_score": 0.92, "absorption_pct": 100,
     "affected_assets": _EQ + ["GLD", "EURUSD=X", "VXX"],
     "description": "NFP mai 2020 : +2.509M ! Attendu -8M. Surprise positive historique. Début de la reprise. SPY +2.6% sur la séance. Fed et marchés reprennent confiance. Mais le taux de chômage mal calculé (mislabeling)."},

    {"name": "NFP Avril 2021 — Miss catastrophique (+266K vs +1000K attendu)",
     "start_date": "2021-05-07", "level": "medium", "category": "event_calendar", "sub_type": "NFP",
     "expected_value": "+1000K", "actual_value": "+266K", "surprise_pct": -75,
     "unit": "K emplois", "impact_score": 0.85, "absorption_pct": 100,
     "affected_assets": _EQ + ["TLT", "GLD", "EURUSD=X"],
     "description": "NFP avril 2021 : +266K vs +1000K attendu. Miss le plus large de l'histoire récente. Fed et marchés ont du mal à lire le post-COVID. Dollar chute. Or monte. Fed repousse toute discussion de taper."},

    {"name": "NFP Octobre 2021 — Forte reprise (+531K)",
     "start_date": "2021-11-05", "level": "short", "category": "event_calendar", "sub_type": "NFP",
     "expected_value": "+450K", "actual_value": "+531K", "surprise_pct": +18,
     "unit": "K emplois", "impact_score": 0.72, "absorption_pct": 100,
     "affected_assets": _EQ + ["TLT", "EURUSD=X"],
     "description": "NFP oct 2021 : +531K, révisions haussières. Marché du travail se resserre. Pression salariale commence. Confirme le taper annoncé en novembre. SPY vers ATH."},

    {"name": "NFP Janvier 2022 — Beat surprise (+467K vs +150K)",
     "start_date": "2022-02-04", "level": "medium", "category": "event_calendar", "sub_type": "NFP",
     "expected_value": "+150K", "actual_value": "+467K", "surprise_pct": +58,
     "unit": "K emplois", "impact_score": 0.80, "absorption_pct": 100,
     "affected_assets": _EQ + ["TLT", "EURUSD=X", "GLD"],
     "description": "NFP janvier 2022 : +467K avec révisions massives à la hausse (+708K révisé pour déc). Marché du travail ultra-chaud. Renforce les arguments hawkish pour mars. TLT -1.5%."},

    {"name": "NFP Juin 2022 — Solide malgré craintes récession (+372K)",
     "start_date": "2022-07-08", "level": "short", "category": "event_calendar", "sub_type": "NFP",
     "expected_value": "+268K", "actual_value": "+372K", "surprise_pct": +39,
     "unit": "K emplois", "impact_score": 0.72, "absorption_pct": 100,
     "affected_assets": _EQ + ["TLT", "EURUSD=X"],
     "description": "NFP juin 2022 : +372K malgré les craintes de récession (GDP Q1 -1.6%, Q2 estimé négatif). Donne à la Fed les munitions pour continuer les hausses agressives."},

    {"name": "NFP Janvier 2023 — Méga-beat choc (+517K vs +185K)",
     "start_date": "2023-02-03", "level": "long", "category": "event_calendar", "sub_type": "NFP",
     "expected_value": "+185K", "actual_value": "+517K", "surprise_pct": +79,
     "unit": "K emplois", "impact_score": 0.90, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "NFP janvier 2023 : +517K ! 2.8x le consensus. Chômage 3.4% (plus bas depuis 1969). Donne à la Fed l'argument pour des hausses supplémentaires. TLT -1.5%. Or -1%. Dollar +0.8%. Remet en question le 'pivot'."},

    {"name": "NFP Juillet 2024 — Choc à la baisse (+114K vs +175K) — Récession panic",
     "start_date": "2024-08-02", "level": "long", "category": "event_calendar", "sub_type": "NFP",
     "expected_value": "+175K", "actual_value": "+114K", "surprise_pct": -38,
     "unit": "K emplois", "impact_score": 0.92, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "NFP juillet 2024 : +114K, massive miss. Chômage 4.3% (Sahm Rule activée → récession signal). Catalyseur du crash août 2024 (SPY -6%, Nikkei -12%). VIX explose à 65. BOJ avait haussé les taux 2 jours avant → double choc."},

    {"name": "NFP Décembre 2024 — Beat fort (+256K vs +155K attendu)",
     "start_date": "2025-01-10", "level": "medium", "category": "event_calendar", "sub_type": "NFP",
     "expected_value": "+155K", "actual_value": "+256K", "surprise_pct": +65,
     "unit": "K emplois", "impact_score": 0.80, "absorption_pct": 100,
     "affected_assets": _EQ + ["TLT", "EURUSD=X", "GLD"],
     "description": "NFP décembre 2024 : +256K, fort beat. Chômage 4.1%. Donne à la Fed un argument supplémentaire pour un 'patient approach'. TLT -1.2%. Repousse les attentes de baisses de taux 2025."},

    # ══════════════════════════════════════════════════════════
    # CPI — INFLATION US (2021-2025)
    # ══════════════════════════════════════════════════════════

    {"name": "CPI Mai 2021 — Premier saut inflationniste majeur (5.0%)",
     "start_date": "2021-06-10", "level": "long", "category": "event_calendar", "sub_type": "CPI",
     "expected_value": "4.7%", "actual_value": "5.0%", "surprise_pct": -12,
     "unit": "% a/a", "impact_score": 0.85, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "CPI mai 2021 : 5.0% a/a, plus haut depuis 2008. Attendu 4.7%. Début de l'ère inflationniste post-COVID. Fed dit 'transitoire'. Gold réagit peu car taux réels encore très négatifs."},

    {"name": "CPI Octobre 2021 — 6.2% (plus haut depuis 31 ans)",
     "start_date": "2021-11-10", "level": "long", "category": "event_calendar", "sub_type": "CPI",
     "expected_value": "5.8%", "actual_value": "6.2%", "surprise_pct": -18,
     "unit": "% a/a", "impact_score": 0.88, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "CPI oct 2021 : 6.2%, plus haut depuis novembre 1990. Attendu 5.8%. 'Transitoire' commence à être abandonné. Powell devra accélérer le taper. TLT -1.5%. Or +0.5% (protection inflation)."},

    {"name": "CPI Décembre 2021 — 7.0% (pic 40 ans)",
     "start_date": "2022-01-12", "level": "long", "category": "event_calendar", "sub_type": "CPI",
     "expected_value": "7.0%", "actual_value": "7.0%", "surprise_pct": 0,
     "unit": "% a/a", "impact_score": 0.85, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "CPI déc 2021 : 7.0% a/a, plus haut depuis 1982. Comme attendu mais confirme la crise inflationniste. Enterre officiellement le mot 'transitoire'. Force la Fed vers un cycle de hausse agressif en 2022."},

    {"name": "CPI Janvier 2022 — 7.5% (40 ans de record + miss hawkish)",
     "start_date": "2022-02-10", "level": "long", "category": "event_calendar", "sub_type": "CPI",
     "expected_value": "7.3%", "actual_value": "7.5%", "surprise_pct": -20,
     "unit": "% a/a", "impact_score": 0.90, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "CPI jan 2022 : 7.5%, au-dessus des 7.3% attendus. 40Y high. James Bullard (St. Louis Fed) appelle à 100pb de hausse d'ici juillet. TLT -1.5%. SPY -1.8%. Le marché prend conscience de l'ampleur du resserrement nécessaire."},

    {"name": "CPI Mai 2022 — 8.6% (record 43 ans, miss hawkish)",
     "start_date": "2022-06-10", "level": "long", "category": "event_calendar", "sub_type": "CPI",
     "expected_value": "8.3%", "actual_value": "8.6%", "surprise_pct": -22,
     "unit": "% a/a", "impact_score": 0.94, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "CPI mai 2022 : 8.6%, plus haut depuis 1981. Attendu 8.3%. Force la Fed à +75pb la semaine suivante (annoncé dimanche soir). SPY -2.9%. Or, parfois hedge inflation, chute aussi car taux réels remontent. Début du bear market 2022."},

    {"name": "CPI Juin 2022 — Pic 9.1% (sommet 43 ans, pire surprise hawkish 2022)",
     "start_date": "2022-07-13", "level": "long", "category": "event_calendar", "sub_type": "CPI",
     "expected_value": "8.8%", "actual_value": "9.1%", "surprise_pct": -25,
     "unit": "% a/a", "impact_score": 0.97, "absorption_pct": 100,
     "affected_assets": _ALL + ["EEM", "USO"],
     "description": "CPI juin 2022 : 9.1% a/a, plus haut depuis novembre 1981. Pire surprise de l'année. Oblige la Fed à considérer +100pb en juillet (finalement +75pb). Dollar index au plus haut, GLD sous pression malgré l'inflation (taux réels montent)."},

    {"name": "CPI Octobre 2022 — 7.7% (inflexion baissière, grosse surprise positive)",
     "start_date": "2022-11-10", "level": "long", "category": "event_calendar", "sub_type": "CPI",
     "expected_value": "7.9%", "actual_value": "7.7%", "surprise_pct": +20,
     "unit": "% a/a", "impact_score": 0.93, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "CPI oct 2022 : 7.7%, première inflexion claire sous les attentes. Attendu 7.9%. Rally historique : SPY +5.5%, NAS +7.4%, GLD +2%, BTC +10%, Dollar -2%. Début du pivot narratif et de la désinflation. Point d'inflexion majeur."},

    {"name": "CPI Décembre 2022 — 6.5% (désinflation confirmée)",
     "start_date": "2023-01-12", "level": "medium", "category": "event_calendar", "sub_type": "CPI",
     "expected_value": "6.5%", "actual_value": "6.5%", "surprise_pct": 0,
     "unit": "% a/a", "impact_score": 0.78, "absorption_pct": 100,
     "affected_assets": _EQ + _RATES + ["GLD", "EURUSD=X"],
     "description": "CPI déc 2022 : 6.5% a/a. Confirme la tendance désinflationniste. 6e mois consécutif de baisse depuis le pic de 9.1%. Marché confirme que le pire est derrière. Bon pour les actifs risqués et obligations."},

    {"name": "CPI Mars 2024 — 3.5% (surprise hawkish, désinflation bloquée)",
     "start_date": "2024-04-10", "level": "medium", "category": "event_calendar", "sub_type": "CPI",
     "expected_value": "3.4%", "actual_value": "3.5%", "surprise_pct": -15,
     "unit": "% a/a", "impact_score": 0.82, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "CPI mars 2024 : 3.5%, au-dessus des 3.4% attendus. 3e mois consécutif au-dessus des attentes. Le 'last mile' est difficile. TLT -1.5%, taux 10Y → 4.5%. Report des baisses Fed de juin à septembre. SPY -1%."},

    {"name": "CPI Mars 2025 — 2.4% (impact tariffs Trump commence à apparaître)",
     "start_date": "2025-04-10", "level": "medium", "category": "event_calendar", "sub_type": "CPI",
     "expected_value": "2.5%", "actual_value": "2.4%", "surprise_pct": +10,
     "unit": "% a/a", "impact_score": 0.75, "absorption_pct": 100,
     "affected_assets": _EQ + _RATES + ["GLD", "EURUSD=X"],
     "description": "CPI mars 2025 : 2.4%, légèrement sous les 2.5% attendus. Dernier mois avant l'impact plein des tarifs Trump (annoncés 2 avril). Le marché sait que l'inflation va remonter. Fed en mode wait-and-see."},

    # ══════════════════════════════════════════════════════════
    # GDP — CROISSANCE US (2020-2025)
    # ══════════════════════════════════════════════════════════

    {"name": "GDP T1 2020 — Premier choc COVID (-4.8% annualisé)",
     "start_date": "2020-04-29", "level": "long", "category": "event_calendar", "sub_type": "GDP",
     "expected_value": "-4.0%", "actual_value": "-4.8%", "surprise_pct": -15,
     "unit": "% ann.", "impact_score": 0.88, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "GDP Q1 2020 (estimé) : -4.8% annualisé. 1er choc COVID sur la croissance. Attendu -4.0%. Pire depuis 2008. Mais le marché sait déjà que Q2 sera catastrophique."},

    {"name": "GDP T2 2020 — Pire contraction de l'histoire US (-32.9%)",
     "start_date": "2020-07-30", "level": "long", "category": "event_calendar", "sub_type": "GDP",
     "expected_value": "-34.7%", "actual_value": "-32.9%", "surprise_pct": +12,
     "unit": "% ann.", "impact_score": 0.92, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "GDP Q2 2020 : -32.9% annualisé. Contraction la plus sévère de l'histoire américaine. Légèrement meilleur qu'attendu (-34.7%) → marché monte légèrement. Marché déjà 'pricé' pour le pire → rallye paradoxal."},

    {"name": "GDP T3 2020 — Rebond en V historique (+33.1%)",
     "start_date": "2020-10-29", "level": "long", "category": "event_calendar", "sub_type": "GDP",
     "expected_value": "+31.0%", "actual_value": "+33.1%", "surprise_pct": +10,
     "unit": "% ann.", "impact_score": 0.88, "absorption_pct": 100,
     "affected_assets": _EQ + ["EURUSD=X", "GLD"],
     "description": "GDP Q3 2020 : +33.1% annualisé. Rebond en V post-COVID historique. Légère beat. Economies restent sous leur potentiel pre-COVID mais la reprise est en marche. Soutient l'élan des marchés."},

    {"name": "GDP T4 2021 — Croissance forte (+6.9%, beat) malgré Omicron",
     "start_date": "2022-01-27", "level": "medium", "category": "event_calendar", "sub_type": "GDP",
     "expected_value": "+5.5%", "actual_value": "+6.9%", "surprise_pct": +20,
     "unit": "% ann.", "impact_score": 0.78, "absorption_pct": 100,
     "affected_assets": _EQ + ["TLT", "GLD", "EURUSD=X"],
     "description": "GDP Q4 2021 : +6.9%, forte beat. Malgré Omicron et les goulots d'étranglement. Ajoute au scénario 'économie forte = Fed peut hiker'. Taux 10Y remontent. TLT perd -2% sur la semaine."},

    {"name": "GDP T1 2022 — Récession surprise (-1.4%, attendu +1.1%)",
     "start_date": "2022-04-28", "level": "long", "category": "event_calendar", "sub_type": "GDP",
     "expected_value": "+1.1%", "actual_value": "-1.4%", "surprise_pct": -55,
     "unit": "% ann.", "impact_score": 0.88, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "GDP Q1 2022 : -1.4%, première contraction depuis COVID. Attendu +1.1%. Choc : stagflation. Inflation à 8.5% et croissance négative. La Fed va-t-elle hiker malgré la récession? Oui → stagflation trade."},

    {"name": "GDP T2 2022 — Récession technique confirmée (-0.9%)",
     "start_date": "2022-07-28", "level": "long", "category": "event_calendar", "sub_type": "GDP",
     "expected_value": "+0.4%", "actual_value": "-0.9%", "surprise_pct": -40,
     "unit": "% ann.", "impact_score": 0.90, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "GDP Q2 2022 : -0.9%. 2e trimestre négatif consécutif → définition technique de récession. Mais le NBER ne le confirme pas (marché du travail fort). Fed tient le cap hawkish malgré la récession. Jour du +75pb FOMC."},

    {"name": "GDP T1 2024 — Miss (1.6% vs 2.4% attendu, stagflation fear)",
     "start_date": "2024-04-25", "level": "medium", "category": "event_calendar", "sub_type": "GDP",
     "expected_value": "+2.4%", "actual_value": "+1.6%", "surprise_pct": -35,
     "unit": "% ann.", "impact_score": 0.82, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "GDP Q1 2024 : +1.6%, grosse déception vs +2.4% attendu. PCE prix à +3.7% (inflation toujours haute). 'Stagflation light' : croissance ralentit mais inflation reste. SPY -1.5%. Retarde les baisses Fed."},

    {"name": "GDP T1 2025 — Contraction (-0.3%) sous choc tarifaire Trump",
     "start_date": "2025-04-30", "level": "long", "category": "event_calendar", "sub_type": "GDP",
     "expected_value": "+0.4%", "actual_value": "-0.3%", "surprise_pct": -40,
     "unit": "% ann.", "impact_score": 0.90, "absorption_pct": 90,
     "affected_assets": _ALL,
     "description": "GDP Q1 2025 : -0.3%, 1ère contraction depuis COVID. Imports explosent avant les tarifs Trump (entreprises stockent). Consommation ralentit. SPY -2%. Débat : récession ou stockage temporaire? Incertitude maximale."},

    # ══════════════════════════════════════════════════════════
    # ISM / PMI — ACTIVITÉ MANUFACTURIÈRE
    # ══════════════════════════════════════════════════════════

    {"name": "ISM Manufacturing Mars 2020 — Effondrement COVID (49.1)",
     "start_date": "2020-04-01", "level": "medium", "category": "event_calendar", "sub_type": "ISM",
     "expected_value": "44.0", "actual_value": "49.1", "surprise_pct": +13,
     "unit": "index", "impact_score": 0.80, "absorption_pct": 100,
     "affected_assets": _EQ + ["GLD", "USO"],
     "description": "ISM Manufacturing mars 2020 : 49.1 (contraction). Meilleur qu'attendu (44.0 consensus). La déstructuration COVID arrive mais plus progressivement que craint. Les services vont bien pire."},

    {"name": "ISM Manufacturing Décembre 2022 — Contraction prolongée (48.4)",
     "start_date": "2023-01-04", "level": "medium", "category": "event_calendar", "sub_type": "ISM",
     "expected_value": "48.5", "actual_value": "48.4", "surprise_pct": -2,
     "unit": "index", "impact_score": 0.72, "absorption_pct": 100,
     "affected_assets": _EQ + ["TLT", "EURUSD=X"],
     "description": "ISM Manufacturing déc 2022 : 48.4, en contraction 2e mois consécutif. Marché commence à pricer un atterrissage plus dur. Mais les services restent solides. Tension entre signaux."},

    {"name": "ISM Manufacturing Juin 2023 — Contraction accélérée (46.0)",
     "start_date": "2023-07-03", "level": "medium", "category": "event_calendar", "sub_type": "ISM",
     "expected_value": "47.2", "actual_value": "46.0", "surprise_pct": -18,
     "unit": "index", "impact_score": 0.75, "absorption_pct": 100,
     "affected_assets": _EQ + ["TLT", "GLD", "EURUSD=X"],
     "description": "ISM Manufacturing juin 2023 : 46.0, plus bas depuis mai 2020. Contraction accélère. Attendu 47.2. Ajoute aux craintes de récession malgré le marché du travail fort. TLT + (récession trade)."},

    {"name": "ISM Manufacturing Juillet 2024 — 46.8 (contraction + NFP miss → récession panic)",
     "start_date": "2024-08-01", "level": "long", "category": "event_calendar", "sub_type": "ISM",
     "expected_value": "48.8", "actual_value": "46.8", "surprise_pct": -25,
     "unit": "index", "impact_score": 0.85, "absorption_pct": 100,
     "affected_assets": _ALL,
     "description": "ISM Manufacturing juil 2024 : 46.8 (miss vs 48.8). Combiné au NFP miss +114K le lendemain, déclenche la panique 'hard landing'. VIX spike, Nikkei -12%, SPY -6%. Catalyseur du grand drawdown d'août 2024."},

    # ══════════════════════════════════════════════════════════
    # BOJ — BANQUE DU JAPON (2020-2025)
    # ══════════════════════════════════════════════════════════

    {"name": "BOJ — Extension COVID QE + achat ETF actions (stimulus japonais)",
     "start_date": "2020-04-27", "level": "medium", "category": "event_calendar", "sub_type": "BOJ",
     "expected_value": "YCC ±20pb + CP", "actual_value": "YCC ±25pb + achats ETF x2", "surprise_pct": +10,
     "unit": "signal", "impact_score": 0.78, "absorption_pct": 100,
     "affected_assets": ["USDJPY=X", "EFA", "GLD"],
     "description": "BOJ double ses achats d'ETF actions (de 6 à 12T¥/an) et élargit le YCC à ±25pb. Soutien sans précédent des actifs risqués japonais. Yen se déprécie modestement. Nikkei bien soutenu."},

    {"name": "BOJ — Maintien YCC malgré spéculation (forte pression vendeuse JGB)",
     "start_date": "2022-06-17", "level": "medium", "category": "event_calendar", "sub_type": "BOJ",
     "expected_value": "ajustement YCC", "actual_value": "YCC maintenu (±25pb)", "surprise_pct": -15,
     "unit": "signal", "impact_score": 0.80, "absorption_pct": 100,
     "affected_assets": ["USDJPY=X", "EFA", "TLT", "GLD"],
     "description": "BOJ maintient le YCC malgré les attaques spéculatives de hedge funds. Kuroda : 'pas de changement de politique'. USD/JPY monte à 135, plus haut depuis 2002. Yen à 24Y low. Pression inflationniste importée au Japon."},

    {"name": "BOJ — Surprise : élargissement YCC de ±25pb à ±50pb",
     "start_date": "2022-12-20", "level": "long", "category": "event_calendar", "sub_type": "BOJ",
     "expected_value": "YCC ±25pb (stable)", "actual_value": "YCC ±50pb", "surprise_pct": -25,
     "unit": "pb", "impact_score": 0.90, "absorption_pct": 100,
     "affected_assets": ["USDJPY=X", "TLT", "GLD", "EFA", "SPY"],
     "description": "BOJ surprend le monde : élargit la bande YCC de ±25pb à ±50pb. Premier mouvement vers normalisation depuis 2016. USD/JPY chute de 137 à 131 en heures. Marché obligataire mondial se vend. Début de la fin du YCC."},

    {"name": "BOJ — Fin des taux négatifs (NIRP) : premier hike depuis 2007",
     "start_date": "2024-03-19", "level": "long", "category": "event_calendar", "sub_type": "BOJ",
     "expected_value": "hold ou +10pb", "actual_value": "+10pb (fin NIRP)", "surprise_pct": +5,
     "unit": "pb", "impact_score": 0.88, "absorption_pct": 100,
     "affected_assets": ["USDJPY=X", "EFA", "TLT", "GLD", "EURUSD=X"],
     "description": "BOJ met fin aux taux négatifs (NIRP), première hausse depuis 2007. Taux 0-0.1%. Fin du YCC. Annonce plus douce qu'attendue sur le 'chemin futur'. USD/JPY chute -1.5%, puis se reprend. Début de la normalisation."},

    {"name": "BOJ — Surprise +15pb → Débâcle carry trade (crash août 2024)",
     "start_date": "2024-07-31", "level": "long", "category": "event_calendar", "sub_type": "BOJ",
     "expected_value": "hold ou +5pb", "actual_value": "+15pb (taux 0.25%)", "surprise_pct": -30,
     "unit": "pb", "impact_score": 0.96, "absorption_pct": 100,
     "affected_assets": ["USDJPY=X", "SPY", "QQQ", "VXX", "GLD", "EFA"],
     "description": "BOJ hausse +15pb de façon surprise. Yen +7% en 48h. USD/JPY 161 → 141. Débâcle massive du carry trade yen : VIX spike à 65 (3e plus haut jamais), Nikkei -12% en 2 jours, SPY -6%. Crise de liquidité mondiale brève mais intense."},

    {"name": "BOJ — Hausse +25pb (Ueda confirme normalisation graduelle)",
     "start_date": "2025-01-24", "level": "medium", "category": "event_calendar", "sub_type": "BOJ",
     "expected_value": "+15pb ou +25pb", "actual_value": "+25pb (taux 0.50%)", "surprise_pct": +5,
     "unit": "pb", "impact_score": 0.80, "absorption_pct": 100,
     "affected_assets": ["USDJPY=X", "EFA", "TLT", "GLD"],
     "description": "BOJ hausse à 0.50%, plus haut depuis 2008. Ueda signale une approche graduelle future. USD/JPY chute -1%. Confirme le cycle de normalisation mais sans panique. Yen en tendance de fond haussière vs USD."},

    # ══════════════════════════════════════════════════════════
    # ECB — BANQUE CENTRALE EUROPÉENNE (2022-2025)
    # ══════════════════════════════════════════════════════════

    {"name": "ECB — Première hausse en 11 ans : +50pb (surprise vs +25pb attendu)",
     "start_date": "2022-07-21", "level": "long", "category": "event_calendar", "sub_type": "ECB",
     "expected_value": "+25pb", "actual_value": "+50pb + TPI anti-fragmentation", "surprise_pct": +15,
     "unit": "pb", "impact_score": 0.90, "absorption_pct": 100,
     "affected_assets": ["EURUSD=X", "EFA", "TLT", "GLD", "GBPUSD=X"],
     "description": "BCE monte +50pb (vs +25 attendu) en première hausse depuis 2011. Lance le TPI (Transmission Protection Instrument) anti-fragmentation. EUR/USD rebond +1.5%. BTP Italie spreads se compriment. Hawkish surprise."},

    {"name": "ECB — Record +75pb (plus grande hausse depuis création Euro)",
     "start_date": "2022-09-08", "level": "long", "category": "event_calendar", "sub_type": "ECB",
     "expected_value": "+75pb", "actual_value": "+75pb (taux 1.25%)", "surprise_pct": 0,
     "unit": "pb", "impact_score": 0.88, "absorption_pct": 100,
     "affected_assets": ["EURUSD=X", "EFA", "TLT", "GLD", "GBPUSD=X"],
     "description": "BCE monte +75pb, le plus fort depuis la création de l'euro en 1999. Inflation eurozone à 9.1%. Lagarde ferme la porte à une récession → marché hausse EUR. Signal que la zone euro va souffrir mais la BCE doit agir."},

    {"name": "ECB — Dernière hausse du cycle : +25pb (pic 4.00%)",
     "start_date": "2023-09-14", "level": "long", "category": "event_calendar", "sub_type": "ECB",
     "expected_value": "+25pb ou hold", "actual_value": "+25pb (fin du cycle)", "surprise_pct": -5,
     "unit": "pb", "impact_score": 0.82, "absorption_pct": 100,
     "affected_assets": ["EURUSD=X", "EFA", "TLT", "GLD"],
     "description": "BCE monte +25pb à 4.00%, signale que c'est probablement la fin. Taux maintenus à 4% pendant 9 mois. EUR/USD perd -0.5% sur la semaine. Marché commence à pricer les baisses 2024."},

    {"name": "ECB — Première baisse de taux depuis 2019 : -25pb",
     "start_date": "2024-06-06", "level": "long", "category": "event_calendar", "sub_type": "ECB",
     "expected_value": "-25pb", "actual_value": "-25pb (taux 3.75%)", "surprise_pct": 0,
     "unit": "pb", "impact_score": 0.82, "absorption_pct": 100,
     "affected_assets": ["EURUSD=X", "EFA", "TLT", "GLD", "GBPUSD=X"],
     "description": "BCE baisse -25pb pour la première fois depuis 2019. Mais projections inflation révisées à la hausse. EUR/USD recule -0.3%. Signal de 'gradualisme' — pas de séries de baisses rapides comme Fed."},

    # ══════════════════════════════════════════════════════════
    # BOE — BANQUE D'ANGLETERRE (2022-2024)
    # ══════════════════════════════════════════════════════════

    {"name": "BOE — +50pb (plus forte hausse depuis 1995) + Truss Budget Crisis",
     "start_date": "2022-08-04", "level": "long", "category": "event_calendar", "sub_type": "BOE",
     "expected_value": "+50pb", "actual_value": "+50pb + avertissement récession", "surprise_pct": -10,
     "unit": "pb", "impact_score": 0.85, "absorption_pct": 100,
     "affected_assets": ["GBPUSD=X", "TLT", "GLD"],
     "description": "BOE monte +50pb, plus fort depuis 1995. Prévoit une récession 'prolongée'. CPI UK à 10.1%. Mini-budget Truss fin septembre va accentuer la crise (gilts crash). GBP perd -10% sur les semaines suivantes."},

    {"name": "BOE — Intervention urgence (Gilts crash, fonds de pension)",
     "start_date": "2022-09-28", "level": "long", "category": "event_calendar", "sub_type": "BOE",
     "expected_value": "QT", "actual_value": "QE urgence temporaire (gilts)", "surprise_pct": +20,
     "unit": "signal", "impact_score": 0.92, "absorption_pct": 100,
     "affected_assets": ["GBPUSD=X", "TLT", "GLD", "VXX", "EFA"],
     "description": "BOE lance un QE d'urgence pour acheter des gilts (obligations UK) après l'effondrement post mini-budget Truss. Gilts à 30Y perdent -30% en une semaine. Fonds de pension LDI en crise de liquidité. GBP à 1.035 (ATL). Crise systémique évitée de justesse."},

    {"name": "BOE — Première baisse de taux depuis COVID : -25pb",
     "start_date": "2024-08-01", "level": "long", "category": "event_calendar", "sub_type": "BOE",
     "expected_value": "hold ou -25pb (50/50)", "actual_value": "-25pb (taux 5.00%)", "surprise_pct": +8,
     "unit": "pb", "impact_score": 0.80, "absorption_pct": 100,
     "affected_assets": ["GBPUSD=X", "EFA", "TLT", "GLD"],
     "description": "BOE baisse -25pb (vote 5-4, très serré). Première baisse depuis mars 2020. Bailey : 'risques inflationnistes se dissipent'. GBP perd -0.5%. Signale le début du cycle d'assouplissement UK, avec prudence."},

    # ══════════════════════════════════════════════════════════
    # PCE / CORE DATA (reference Fed)
    # ══════════════════════════════════════════════════════════

    {"name": "PCE Janvier 2024 — Core PCE 2.8% (inflation sticky, cut repoussé)",
     "start_date": "2024-02-29", "level": "medium", "category": "event_calendar", "sub_type": "PCE",
     "expected_value": "2.4%", "actual_value": "2.8%", "surprise_pct": -25,
     "unit": "% a/a", "impact_score": 0.80, "absorption_pct": 100,
     "affected_assets": _EQ + ["TLT", "GLD", "EURUSD=X"],
     "description": "Core PCE jan 2024 : 2.8% a/a, au-dessus de 2.4% attendu et des 2.6% de décembre. L'indicateur préféré de la Fed refuse de descendre. Repousse les anticipations de baisse mars → juin. TLT -1.2%."},

    {"name": "PCE Septembre 2024 — Core PCE 2.6% (vers 2% mais résistant)",
     "start_date": "2024-10-31", "level": "short", "category": "event_calendar", "sub_type": "PCE",
     "expected_value": "2.6%", "actual_value": "2.6%", "surprise_pct": 0,
     "unit": "% a/a", "impact_score": 0.68, "absorption_pct": 100,
     "affected_assets": _EQ + ["TLT", "GLD"],
     "description": "Core PCE sept 2024 : 2.6%, comme attendu. Toujours au-dessus de l'objectif 2%. Confirme que la désinflation 'last mile' est lente. Marché accepte le 'higher for longer' même en phase de baisses."},
]


def bootstrap_eco_events(force: bool = False) -> Dict[str, Any]:
    """
    Insert curated economic calendar events into market_events DB.
    Idempotent: skips events whose name already exists.
    Returns: {inserted, skipped, errors, total}
    """
    from services.database import get_all_market_events, save_market_event

    existing = {ev.get("name", "") for ev in get_all_market_events()}

    if force:
        from services.database import delete_market_event, get_all_market_events as _gae
        eco_names = {e["name"] for e in ECO_EVENTS}
        for ev in _gae():
            if ev.get("name") in eco_names:
                delete_market_event(ev["id"])
        existing = set()
        logger.info("[eco_bootstrap] Force: existing eco events deleted")

    import json
    inserted = skipped = errors = 0
    for ev in ECO_EVENTS:
        if ev["name"] in existing:
            skipped += 1
            continue
        try:
            save_market_event({
                "name":           ev["name"],
                "start_date":     ev["start_date"],
                "end_date":       ev.get("end_date"),
                "level":          ev["level"],
                "category":       ev["category"],
                "sub_type":       ev.get("sub_type"),
                "description":    ev.get("description", ""),
                "market_impact":  ev.get("description", "")[:80],
                "affected_assets": ev.get("affected_assets", []),
                "impact_score":   ev.get("impact_score", 0.75),
                "expected_value": ev.get("expected_value"),
                "actual_value":   ev.get("actual_value"),
                "surprise_pct":   ev.get("surprise_pct"),
                "unit":           ev.get("unit"),
                "absorption_pct": ev.get("absorption_pct", 100),
                "origin":         "bootstrap_eco",
            })
            inserted += 1
        except Exception as e:
            logger.warning(f"[eco_bootstrap] Error inserting '{ev['name'][:40]}': {e}")
            errors += 1

    from services.database import count_market_events
    total = count_market_events()
    logger.info(f"[eco_bootstrap] inserted={inserted} skipped={skipped} errors={errors} total={total}")
    return {"inserted": inserted, "skipped": skipped, "errors": errors, "total": total}
