from enum import Enum
from typing import Any

from pydantic import BaseModel, Field


class PlatformId(str, Enum):
    NINJA = "ninjatrader"
    MANUAL = "manual"


class IntegrationPhase(str, Enum):
    """Maturite du connecteur."""

    PLANNED = "planned"  # stub — pas encore branche
    DISCIPLINE = "discipline"  # garde-fou OK / REFUS
    EXECUTION = "execution"  # ordres via API broker


class TradeIntent(BaseModel):
    """Demande de trade normalisee — toutes plateformes."""

    platform: PlatformId
    ticker: str
    action: str
    source: str = "unknown"
    strategy: str | None = None
    price: float | None = None
    quantity: float | None = None
    stop_loss: float | None = None
    take_profit: float | None = None
    raw: dict[str, Any] = Field(default_factory=dict)


class ConnectorStatus(BaseModel):
    platform: PlatformId
    name: str
    phase: IntegrationPhase
    enabled: bool
    discipline_manual: bool = True
    discipline_auto: bool = False
    connected: bool = False  # liaison reelle avec le logiciel (EA, API, webhook actif, etc.)
    message: str
