"""
Bootstrap default event categories with instrument impact sensitivities.
Each category has default_impacts: list of {instrument_id, sensitivity (0-1),
typical_direction, notes}.
sensitivity = how strongly this instrument type is typically affected.
typical_direction = usual bias (bullish/bearish/neutral/depends_on_outcome).
"""
from typing import List, Dict, Any

ALL_INSTRUMENTS = [
    "SPY","QQQ","IWM","EEM","EFA",
    "GLD","SLV","USO","UNG","TLT",
    "HYG","EURUSD=X","USDJPY=X","GBPUSD=X",
    "VXX","AAPL","NVDA","GS","XOM","BTC-USD",
]

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

    # ═══════════════════════════════════════════════════════
    # EVENT CALENDAR
    # ═══════════════════════════════════════════════════════

    {
        "name": "FOMC — Décision de taux",
        "type": "event_calendar",
        "sub_type": "FOMC",
        "description": "Décision du Federal Open Market Committee sur les taux directeurs US.",
        "default_impacts": [
            {"instrument_id": "SPY",      "sensitivity": 0.88, "typical_direction": "depends_on_outcome", "notes": "Hausse = baisse. Baisse = hausse. Surprise domine."},
            {"instrument_id": "QQQ",      "sensitivity": 0.90, "typical_direction": "depends_on_outcome", "notes": "Très sensible aux taux réels — plus volatile que SPY sur les FOMC."},
            {"instrument_id": "IWM",      "sensitivity": 0.80, "typical_direction": "depends_on_outcome", "notes": "Small caps très sensibles au crédit et aux taux courts."},
            {"instrument_id": "TLT",      "sensitivity": 0.95, "typical_direction": "depends_on_outcome", "notes": "Relation directe : hausse = TLT baisse, pivot = TLT monte."},
            {"instrument_id": "HYG",      "sensitivity": 0.82, "typical_direction": "depends_on_outcome", "notes": "Spreads HY se compriment (dovish) ou s'écartent (hawkish)."},
            {"instrument_id": "GLD",      "sensitivity": 0.78, "typical_direction": "depends_on_outcome", "notes": "Or inverse aux taux réels. Dovish = gold up. Hawkish = gold down."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.85, "typical_direction": "depends_on_outcome", "notes": "Différentiel Fed/BCE. Hawkish Fed = USD fort = EUR baisse."},
            {"instrument_id": "USDJPY=X", "sensitivity": 0.88, "typical_direction": "depends_on_outcome", "notes": "Différentiel US-JP. Hawkish Fed = USD/JPY monte."},
            {"instrument_id": "GBPUSD=X", "sensitivity": 0.72, "typical_direction": "depends_on_outcome", "notes": "Impact via USD strength/weakness."},
            {"instrument_id": "VXX",      "sensitivity": 0.80, "typical_direction": "depends_on_outcome", "notes": "Vol spike si surprise. Compression si résultat attendu."},
            {"instrument_id": "BTC-USD",  "sensitivity": 0.72, "typical_direction": "depends_on_outcome", "notes": "Actif risqué/liquidité. Dovish Fed = BTC monte."},
            {"instrument_id": "GS",       "sensitivity": 0.78, "typical_direction": "depends_on_outcome", "notes": "Banque sensible à la courbe des taux et aux conditions crédit."},
            {"instrument_id": "EEM",      "sensitivity": 0.70, "typical_direction": "depends_on_outcome", "notes": "USD fort = pression sur EM (dette USD). Dovish = flux EM."},
        ]
    },

    {
        "name": "NFP — Non-Farm Payrolls",
        "type": "event_calendar",
        "sub_type": "NFP",
        "description": "Publication mensuelle de l'emploi non-agricole US.",
        "default_impacts": [
            {"instrument_id": "SPY",      "sensitivity": 0.78, "typical_direction": "depends_on_outcome", "notes": "Beat = bon pour actions si pas de peur de la Fed. Miss = récession fear."},
            {"instrument_id": "QQQ",      "sensitivity": 0.75, "typical_direction": "depends_on_outcome", "notes": "Moins sensible que SPY sauf si choc majeur."},
            {"instrument_id": "IWM",      "sensitivity": 0.80, "typical_direction": "bullish_if_beat",    "notes": "Small caps très sensibles à la croissance domestique."},
            {"instrument_id": "TLT",      "sensitivity": 0.82, "typical_direction": "depends_on_outcome", "notes": "Beat = TLT baisse (Fed plus hawkish). Miss = TLT monte (récession trade)."},
            {"instrument_id": "HYG",      "sensitivity": 0.75, "typical_direction": "bullish_if_beat",    "notes": "Bon emploi = défauts faibles = HY spreads se compriment."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.72, "typical_direction": "depends_on_outcome", "notes": "Beat = USD fort. Miss = USD faible."},
            {"instrument_id": "USDJPY=X", "sensitivity": 0.75, "typical_direction": "depends_on_outcome", "notes": "Beat = USD/JPY monte."},
            {"instrument_id": "GLD",      "sensitivity": 0.65, "typical_direction": "depends_on_outcome", "notes": "Beat = or baisse (taux montent). Miss = or monte (récession hedge)."},
            {"instrument_id": "VXX",      "sensitivity": 0.70, "typical_direction": "depends_on_outcome", "notes": "Miss majeur = vol spike. Beat en ligne = vol compression."},
        ]
    },

    {
        "name": "CPI — Inflation US",
        "type": "event_calendar",
        "sub_type": "CPI",
        "description": "Publication mensuelle de l'indice des prix à la consommation US.",
        "default_impacts": [
            {"instrument_id": "SPY",      "sensitivity": 0.82, "typical_direction": "depends_on_outcome", "notes": "CPI > attendu = hawkish Fed = actions baissent."},
            {"instrument_id": "QQQ",      "sensitivity": 0.85, "typical_direction": "depends_on_outcome", "notes": "QQQ plus sensible que SPY via taux réels."},
            {"instrument_id": "TLT",      "sensitivity": 0.90, "typical_direction": "depends_on_outcome", "notes": "CPI > attendu = TLT vend massivement. En-dessous = TLT rally."},
            {"instrument_id": "GLD",      "sensitivity": 0.80, "typical_direction": "depends_on_outcome", "notes": "CPI > attendu = d'abord bearish or (taux réels montent). Mais LT = hedge."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.75, "typical_direction": "depends_on_outcome", "notes": "CPI hot = USD fort = EUR baisse."},
            {"instrument_id": "USDJPY=X", "sensitivity": 0.78, "typical_direction": "depends_on_outcome", "notes": "CPI hot = Fed hawkish = USD/JPY monte."},
            {"instrument_id": "HYG",      "sensitivity": 0.72, "typical_direction": "depends_on_outcome", "notes": "CPI hot = risque de hausse des taux = spreads s'écartent."},
            {"instrument_id": "VXX",      "sensitivity": 0.75, "typical_direction": "depends_on_outcome", "notes": "Surprise majeure dans les 2 sens = vol spike."},
            {"instrument_id": "BTC-USD",  "sensitivity": 0.65, "typical_direction": "depends_on_outcome", "notes": "CPI hot = taux montent = liquidité se réduit = BTC baisse."},
        ]
    },

    {
        "name": "GDP — Croissance US",
        "type": "event_calendar",
        "sub_type": "GDP",
        "description": "Publication trimestrielle du PIB américain (estimé, révisé, final).",
        "default_impacts": [
            {"instrument_id": "SPY",      "sensitivity": 0.78, "typical_direction": "bullish_if_beat",    "notes": "Croissance forte = bénéfices. Récession = bear market."},
            {"instrument_id": "QQQ",      "sensitivity": 0.75, "typical_direction": "bullish_if_beat",    "notes": "Corrélé mais moins direct que SPY."},
            {"instrument_id": "IWM",      "sensitivity": 0.85, "typical_direction": "bullish_if_beat",    "notes": "Small caps très corrélées au cycle domestique."},
            {"instrument_id": "TLT",      "sensitivity": 0.78, "typical_direction": "bearish_if_beat",    "notes": "Croissance forte = taux montent = TLT baisse."},
            {"instrument_id": "HYG",      "sensitivity": 0.80, "typical_direction": "bullish_if_beat",    "notes": "Croissance forte = défauts faibles = HY se comprime."},
            {"instrument_id": "GLD",      "sensitivity": 0.60, "typical_direction": "depends_on_outcome", "notes": "Impact indirect via taux réels."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.65, "typical_direction": "depends_on_outcome", "notes": "PIB fort = USD fort si surprise."},
            {"instrument_id": "VXX",      "sensitivity": 0.72, "typical_direction": "depends_on_outcome", "notes": "Récession technique = vol spike. Beat = vol compression."},
            {"instrument_id": "GS",       "sensitivity": 0.75, "typical_direction": "bullish_if_beat",    "notes": "Croissance forte = M&A, trading, activité bancaire."},
            {"instrument_id": "XOM",      "sensitivity": 0.68, "typical_direction": "bullish_if_beat",    "notes": "Croissance = demande énergétique plus forte."},
        ]
    },

    {
        "name": "PCE — Core PCE (indicateur Fed)",
        "type": "event_calendar",
        "sub_type": "PCE",
        "description": "Core PCE Price Index — indicateur d'inflation de référence de la Fed.",
        "default_impacts": [
            {"instrument_id": "SPY",      "sensitivity": 0.75, "typical_direction": "depends_on_outcome", "notes": "Similaire au CPI mais moins volatile. Impact si surprise notable."},
            {"instrument_id": "TLT",      "sensitivity": 0.82, "typical_direction": "depends_on_outcome", "notes": "Hot PCE = taux montent = TLT vend."},
            {"instrument_id": "GLD",      "sensitivity": 0.72, "typical_direction": "depends_on_outcome", "notes": "Impact via taux réels."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.68, "typical_direction": "depends_on_outcome", "notes": "Hot PCE = Fed hawkish = USD fort."},
            {"instrument_id": "QQQ",      "sensitivity": 0.78, "typical_direction": "depends_on_outcome", "notes": "QQQ très sensible aux taux réels."},
        ]
    },

    {
        "name": "ISM Manufacturing",
        "type": "event_calendar",
        "sub_type": "ISM",
        "description": "ISM Manufacturing PMI — activité industrielle US (>50 expansion, <50 contraction).",
        "default_impacts": [
            {"instrument_id": "IWM",      "sensitivity": 0.80, "typical_direction": "bullish_if_beat",    "notes": "Très corrélé à l'industrie domestique."},
            {"instrument_id": "SPY",      "sensitivity": 0.68, "typical_direction": "bullish_if_beat",    "notes": "Indicateur de cycle économique."},
            {"instrument_id": "USO",      "sensitivity": 0.65, "typical_direction": "bullish_if_beat",    "notes": "Production industrielle forte = demande énergie."},
            {"instrument_id": "XOM",      "sensitivity": 0.65, "typical_direction": "bullish_if_beat",    "notes": "Similaire à USO."},
            {"instrument_id": "TLT",      "sensitivity": 0.65, "typical_direction": "bearish_if_beat",    "notes": "Expansion = risque de hausse taux."},
            {"instrument_id": "VXX",      "sensitivity": 0.62, "typical_direction": "depends_on_outcome", "notes": "Miss sévère déclenche vol."},
        ]
    },

    {
        "name": "BOJ — Décision de taux",
        "type": "event_calendar",
        "sub_type": "BOJ",
        "description": "Décision de politique monétaire de la Banque du Japon — YCC, NIRP, normalisation.",
        "default_impacts": [
            {"instrument_id": "USDJPY=X", "sensitivity": 0.97, "typical_direction": "depends_on_outcome", "notes": "DRIVER PRINCIPAL. Hausse surprise = JPY fort = USD/JPY chute."},
            {"instrument_id": "EFA",      "sensitivity": 0.82, "typical_direction": "depends_on_outcome", "notes": "Japon = composante majeure de l'EAFE."},
            {"instrument_id": "GLD",      "sensitivity": 0.68, "typical_direction": "depends_on_outcome", "notes": "Normalisation BOJ = or peut monter (diversification réserves)."},
            {"instrument_id": "TLT",      "sensitivity": 0.72, "typical_direction": "depends_on_outcome", "notes": "BOJ hawkish = hausse taux Japon = JGB concurrence UST."},
            {"instrument_id": "VXX",      "sensitivity": 0.80, "typical_direction": "bullish_if_surprise","notes": "BOJ surprise = carry trade unwind = vol spike mondial."},
            {"instrument_id": "SPY",      "sensitivity": 0.65, "typical_direction": "depends_on_outcome", "notes": "Via carry trade unwind (BOJ hawkish → vente actifs risqués)."},
            {"instrument_id": "BTC-USD",  "sensitivity": 0.58, "typical_direction": "bearish_if_hawkish", "notes": "Risk-off si carry unwind."},
        ]
    },

    {
        "name": "ECB — Décision de taux",
        "type": "event_calendar",
        "sub_type": "ECB",
        "description": "Décision de politique monétaire de la Banque Centrale Européenne.",
        "default_impacts": [
            {"instrument_id": "EURUSD=X", "sensitivity": 0.95, "typical_direction": "depends_on_outcome", "notes": "DRIVER PRINCIPAL. Hawkish ECB = EUR fort. Dovish = EUR faible."},
            {"instrument_id": "GBPUSD=X", "sensitivity": 0.72, "typical_direction": "depends_on_outcome", "notes": "Impact via USD et sentiment zone euro."},
            {"instrument_id": "EFA",      "sensitivity": 0.85, "typical_direction": "depends_on_outcome", "notes": "Zone euro = composante majeure EAFE."},
            {"instrument_id": "TLT",      "sensitivity": 0.65, "typical_direction": "depends_on_outcome", "notes": "Politique BCE influence flux globaux vers Treasuries."},
            {"instrument_id": "GLD",      "sensitivity": 0.60, "typical_direction": "depends_on_outcome", "notes": "BCE hawkish = EUR fort = or en EUR baisse."},
            {"instrument_id": "VXX",      "sensitivity": 0.62, "typical_direction": "depends_on_outcome", "notes": "Surprise ECB peut déclencher vol."},
        ]
    },

    {
        "name": "BOE — Décision de taux",
        "type": "event_calendar",
        "sub_type": "BOE",
        "description": "Décision de politique monétaire de la Bank of England.",
        "default_impacts": [
            {"instrument_id": "GBPUSD=X", "sensitivity": 0.95, "typical_direction": "depends_on_outcome", "notes": "DRIVER PRINCIPAL. Hawkish BOE = GBP fort. Dovish = GBP faible."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.55, "typical_direction": "depends_on_outcome", "notes": "Impact indirect via sentiment EUR/GBP."},
            {"instrument_id": "TLT",      "sensitivity": 0.52, "typical_direction": "depends_on_outcome", "notes": "Impact global limité sauf si crise gilts (2022)."},
            {"instrument_id": "VXX",      "sensitivity": 0.55, "typical_direction": "depends_on_outcome", "notes": "Crise gilt-style = vol spike."},
        ]
    },

    {
        "name": "OPEC+ — Décision de production",
        "type": "event_calendar",
        "sub_type": "OPEC",
        "description": "Réunion OPEC+ : décision de quotas de production pétrolière.",
        "default_impacts": [
            {"instrument_id": "USO",      "sensitivity": 0.95, "typical_direction": "depends_on_outcome", "notes": "DRIVER PRINCIPAL. Coupes = oil monte. Augmentation = oil baisse."},
            {"instrument_id": "XOM",      "sensitivity": 0.88, "typical_direction": "depends_on_outcome", "notes": "Prix pétrole = cash-flow XOM."},
            {"instrument_id": "EEM",      "sensitivity": 0.68, "typical_direction": "depends_on_outcome", "notes": "Exportateurs EM bénéficient des coupes."},
            {"instrument_id": "GLD",      "sensitivity": 0.55, "typical_direction": "depends_on_outcome", "notes": "Oil choc = inflation = gold monte parfois."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.58, "typical_direction": "depends_on_outcome", "notes": "Pétrole cher = pression sur l'Europe importatrice = EUR faible."},
            {"instrument_id": "VXX",      "sensitivity": 0.65, "typical_direction": "depends_on_outcome", "notes": "Surprise coupe majeure = spike vol court terme."},
            {"instrument_id": "SPY",      "sensitivity": 0.60, "typical_direction": "depends_on_outcome", "notes": "Oil choc = inflation = stagflation fear."},
            {"instrument_id": "TLT",      "sensitivity": 0.58, "typical_direction": "depends_on_outcome", "notes": "Oil choc = inflation = taux montent = TLT baisse."},
        ]
    },

    {
        "name": "EIA — Stocks pétroliers",
        "type": "event_calendar",
        "sub_type": "EIA",
        "description": "Rapport hebdomadaire EIA sur les stocks de pétrole brut US.",
        "default_impacts": [
            {"instrument_id": "USO",      "sensitivity": 0.82, "typical_direction": "depends_on_outcome", "notes": "Build (hausse stocks) = baissier. Draw (baisse stocks) = haussier."},
            {"instrument_id": "XOM",      "sensitivity": 0.72, "typical_direction": "depends_on_outcome", "notes": "Corrélé au prix pétrole."},
            {"instrument_id": "UNG",      "sensitivity": 0.45, "typical_direction": "neutral",            "notes": "Impact indirect via sentiment énergie."},
        ]
    },

    # ═══════════════════════════════════════════════════════
    # GEOPOLITICAL
    # ═══════════════════════════════════════════════════════

    {
        "name": "Guerre — Moyen-Orient",
        "type": "geopolitical",
        "sub_type": "War",
        "description": "Conflit militaire ou escalade au Moyen-Orient (Iran, Israël, Yemen, Golfe Persique).",
        "default_impacts": [
            {"instrument_id": "USO",      "sensitivity": 0.92, "typical_direction": "bullish",            "notes": "DRIVER PRINCIPAL. Menace sur les livraisons du Golfe Persique."},
            {"instrument_id": "GLD",      "sensitivity": 0.85, "typical_direction": "bullish",            "notes": "Safe haven classique en crise géopolitique."},
            {"instrument_id": "VXX",      "sensitivity": 0.88, "typical_direction": "bullish",            "notes": "Choc géopolitique = vol spike immédiat."},
            {"instrument_id": "XOM",      "sensitivity": 0.80, "typical_direction": "bullish",            "notes": "Prime géopolitique sur le pétrole."},
            {"instrument_id": "SPY",      "sensitivity": 0.75, "typical_direction": "bearish",            "notes": "Risk-off. Ampleur dépend de la durée et de l'escalade."},
            {"instrument_id": "QQQ",      "sensitivity": 0.72, "typical_direction": "bearish",            "notes": "Tech vend en risk-off."},
            {"instrument_id": "TLT",      "sensitivity": 0.72, "typical_direction": "bullish",            "notes": "Fuite vers la qualité."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.68, "typical_direction": "bearish",            "notes": "USD safe haven. EUR exposé via énergie."},
            {"instrument_id": "EEM",      "sensitivity": 0.72, "typical_direction": "bearish",            "notes": "Risk-off pèse sur EM. Pays importateurs pétrole souffrent."},
            {"instrument_id": "USDJPY=X", "sensitivity": 0.65, "typical_direction": "bearish",            "notes": "JPY safe haven = USD/JPY baisse."},
            {"instrument_id": "BTC-USD",  "sensitivity": 0.60, "typical_direction": "bearish",            "notes": "Risk-off en phase initiale. Puis possible refuge si dévaluation USD."},
        ]
    },

    {
        "name": "Guerre — Russie / Ukraine",
        "type": "geopolitical",
        "sub_type": "War",
        "description": "Escalade ou désescalade du conflit russo-ukrainien. Impact sur énergie, céréales, EM.",
        "default_impacts": [
            {"instrument_id": "USO",      "sensitivity": 0.85, "typical_direction": "bullish",            "notes": "Russie = grand exportateur. Sanctions = offre réduite."},
            {"instrument_id": "UNG",      "sensitivity": 0.80, "typical_direction": "bullish",            "notes": "Gaz russe = composante clé approvisionnement Europe."},
            {"instrument_id": "GLD",      "sensitivity": 0.82, "typical_direction": "bullish",            "notes": "Safe haven + incertitude systémique."},
            {"instrument_id": "EFA",      "sensitivity": 0.78, "typical_direction": "bearish",            "notes": "Europe exposée énergétiquement et économiquement."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.80, "typical_direction": "bearish",            "notes": "EUR exposé au choc énergétique et à la croissance européenne."},
            {"instrument_id": "VXX",      "sensitivity": 0.85, "typical_direction": "bullish",            "notes": "Escalade = spike vol immédiat."},
            {"instrument_id": "SPY",      "sensitivity": 0.68, "typical_direction": "bearish",            "notes": "Risk-off, plus modéré car US moins exposé."},
            {"instrument_id": "EEM",      "sensitivity": 0.72, "typical_direction": "bearish",            "notes": "EM exportateurs céréales et énergie impactés."},
            {"instrument_id": "TLT",      "sensitivity": 0.68, "typical_direction": "bullish",            "notes": "Fuite vers qualité en escalade."},
            {"instrument_id": "XOM",      "sensitivity": 0.72, "typical_direction": "bullish",            "notes": "Prix pétrole/gaz monte = XOM bénéficie."},
        ]
    },

    {
        "name": "Sanctions — Pétrole / Énergie",
        "type": "geopolitical",
        "sub_type": "Sanctions",
        "description": "Sanctions énergétiques (Russie, Iran, Venezuela) ou perturbation supply pétrolier.",
        "default_impacts": [
            {"instrument_id": "USO",      "sensitivity": 0.90, "typical_direction": "bullish",            "notes": "Offre réduite = prix monte."},
            {"instrument_id": "XOM",      "sensitivity": 0.82, "typical_direction": "bullish",            "notes": "Bénéfice du prix élevé et du remplacement de supply."},
            {"instrument_id": "GLD",      "sensitivity": 0.68, "typical_direction": "bullish",            "notes": "Inflation énergie = or monte."},
            {"instrument_id": "TLT",      "sensitivity": 0.62, "typical_direction": "bearish",            "notes": "Inflation énergie = taux montent."},
            {"instrument_id": "SPY",      "sensitivity": 0.65, "typical_direction": "bearish",            "notes": "Stagflation si choc sévère."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.68, "typical_direction": "bearish",            "notes": "Europe plus exposée que US."},
        ]
    },

    {
        "name": "Chine — Taiwan / Tensions géopolitiques",
        "type": "geopolitical",
        "sub_type": "China",
        "description": "Escalade militaire ou diplomatique Chine-Taiwan, mers de Chine.",
        "default_impacts": [
            {"instrument_id": "VXX",      "sensitivity": 0.95, "typical_direction": "bullish",            "notes": "Choc systémique maximal si escalade."},
            {"instrument_id": "NVDA",     "sensitivity": 0.92, "typical_direction": "bearish",            "notes": "Taiwan = TSMC. Supply chain semi-conducteurs bloquée."},
            {"instrument_id": "QQQ",      "sensitivity": 0.85, "typical_direction": "bearish",            "notes": "Tech exposé via supply chain Asie."},
            {"instrument_id": "SPY",      "sensitivity": 0.80, "typical_direction": "bearish",            "notes": "Risk-off systémique."},
            {"instrument_id": "GLD",      "sensitivity": 0.88, "typical_direction": "bullish",            "notes": "Safe haven ultime."},
            {"instrument_id": "TLT",      "sensitivity": 0.75, "typical_direction": "bullish",            "notes": "Fuite vers qualité."},
            {"instrument_id": "EEM",      "sensitivity": 0.90, "typical_direction": "bearish",            "notes": "Chine = composante majeure EEM."},
            {"instrument_id": "AAPL",     "sensitivity": 0.85, "typical_direction": "bearish",            "notes": "Apple : fabrication en Chine + ventes chinoises menacées."},
            {"instrument_id": "USDJPY=X", "sensitivity": 0.70, "typical_direction": "bearish",            "notes": "JPY safe haven."},
            {"instrument_id": "BTC-USD",  "sensitivity": 0.65, "typical_direction": "bearish",            "notes": "Risk-off initial."},
        ]
    },

    {
        "name": "Guerre commerciale / Tarifs douaniers",
        "type": "geopolitical",
        "sub_type": "TradeWar",
        "description": "Annonce de tarifs douaniers, escalade guerre commerciale US-Chine ou US-UE.",
        "default_impacts": [
            {"instrument_id": "EEM",      "sensitivity": 0.85, "typical_direction": "bearish",            "notes": "Exportateurs EM très exposés."},
            {"instrument_id": "QQQ",      "sensitivity": 0.80, "typical_direction": "bearish",            "notes": "Tech exposé via supply chain et marchés chinois."},
            {"instrument_id": "AAPL",     "sensitivity": 0.88, "typical_direction": "bearish",            "notes": "Apple : tarifs sur produits fabriqués en Chine."},
            {"instrument_id": "NVDA",     "sensitivity": 0.82, "typical_direction": "bearish",            "notes": "Export controls sur chips."},
            {"instrument_id": "SPY",      "sensitivity": 0.75, "typical_direction": "bearish",            "notes": "Stagflation domestique + récession mondiale."},
            {"instrument_id": "GLD",      "sensitivity": 0.72, "typical_direction": "bullish",            "notes": "Hedge inflation + incertitude."},
            {"instrument_id": "TLT",      "sensitivity": 0.65, "typical_direction": "depends_on_outcome", "notes": "Récession = haussier TLT. Inflation = baissier."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.68, "typical_direction": "bearish",            "notes": "USD peut se renforcer en position de force."},
            {"instrument_id": "VXX",      "sensitivity": 0.80, "typical_direction": "bullish",            "notes": "Incertitude = vol monte."},
            {"instrument_id": "USO",      "sensitivity": 0.60, "typical_direction": "bearish",            "notes": "Récession mondiale = demande pétrole baisse."},
            {"instrument_id": "XOM",      "sensitivity": 0.58, "typical_direction": "bearish",            "notes": "Même logique que USO."},
        ]
    },

    {
        "name": "Crise bancaire / Stress systémique",
        "type": "geopolitical",
        "sub_type": "Banking",
        "description": "Faillite bancaire, crise de liquidité, risque systémique (type SVB, Lehman, gilts UK).",
        "default_impacts": [
            {"instrument_id": "VXX",      "sensitivity": 0.97, "typical_direction": "bullish",            "notes": "Crise systémique = vol spike maximal."},
            {"instrument_id": "HYG",      "sensitivity": 0.92, "typical_direction": "bearish",            "notes": "Spreads HY explosent en crise de crédit."},
            {"instrument_id": "GS",       "sensitivity": 0.90, "typical_direction": "bearish",            "notes": "Banques directement exposées."},
            {"instrument_id": "GLD",      "sensitivity": 0.85, "typical_direction": "bullish",            "notes": "Safe haven ultime."},
            {"instrument_id": "TLT",      "sensitivity": 0.80, "typical_direction": "bullish",            "notes": "Fuite vers la qualité + attente pivot Fed."},
            {"instrument_id": "SPY",      "sensitivity": 0.82, "typical_direction": "bearish",            "notes": "Contagion systémique."},
            {"instrument_id": "IWM",      "sensitivity": 0.88, "typical_direction": "bearish",            "notes": "Small caps très dépendantes du crédit bancaire régional."},
            {"instrument_id": "BTC-USD",  "sensitivity": 0.72, "typical_direction": "depends_on_outcome", "notes": "Initial sell-off, puis possible rally si pivot Fed."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.72, "typical_direction": "depends_on_outcome", "notes": "USD safe haven. EUR exposé si crise zone euro."},
            {"instrument_id": "USDJPY=X", "sensitivity": 0.70, "typical_direction": "bearish",            "notes": "Risk-off = JPY monte."},
        ]
    },

    {
        "name": "Stimulus Chine / PBOC",
        "type": "geopolitical",
        "sub_type": "China",
        "description": "Annonce de stimulus économique par Pékin ou décision d'assouplissement de la PBOC.",
        "default_impacts": [
            {"instrument_id": "EEM",      "sensitivity": 0.92, "typical_direction": "bullish",            "notes": "Chine = moteur principal des émergents."},
            {"instrument_id": "GLD",      "sensitivity": 0.75, "typical_direction": "bullish",            "notes": "Stimulus = inflation + demande bijouterie/physique."},
            {"instrument_id": "USO",      "sensitivity": 0.80, "typical_direction": "bullish",            "notes": "Chine = 1er importateur pétrole. Stimulus = demande monte."},
            {"instrument_id": "SLV",      "sensitivity": 0.78, "typical_direction": "bullish",            "notes": "Chine = 1er consommateur industriel argent."},
            {"instrument_id": "XOM",      "sensitivity": 0.70, "typical_direction": "bullish",            "notes": "Demande pétrole Chine monte."},
            {"instrument_id": "EFA",      "sensitivity": 0.70, "typical_direction": "bullish",            "notes": "Europe/Japon exportent vers Chine."},
            {"instrument_id": "SPY",      "sensitivity": 0.60, "typical_direction": "bullish",            "notes": "Sentiment global améliore."},
            {"instrument_id": "EURUSD=X", "sensitivity": 0.58, "typical_direction": "bullish",            "notes": "Risk-on = USD faible."},
        ]
    },
]


def bootstrap_impact_categories(force: bool = False) -> Dict[str, Any]:
    """Insert default impact categories. Idempotent if force=False."""
    from services.database import upsert_event_category, get_all_event_categories

    existing = {c["name"] for c in get_all_event_categories()}
    inserted = skipped = 0
    for cat in CATEGORIES:
        if not force and cat["name"] in existing:
            skipped += 1
            continue
        upsert_event_category(cat)
        inserted += 1

    return {"inserted": inserted, "skipped": skipped, "total": len(CATEGORIES)}
