from pathlib import Path

from pydantic_settings import BaseSettings, SettingsConfigDict

from runtime.paths import resolve_env_file

_PROJECT_ROOT = Path(__file__).resolve().parents[1]


class Settings(BaseSettings):
    model_config = SettingsConfigDict(
        env_file=str(resolve_env_file()),
        env_file_encoding="utf-8",
    )
    webhook_secret: str = "change-me-before-production"
    execution_mode: str = "hybrid"  # hybrid | auto
    host: str = "0.0.0.0"
    port: int = 8080

    # Kill switch — TRADING_ENABLED=false bloque tout nouvel ordre
    trading_enabled: bool = True

    # Session (fuseau IANA, ex. Europe/Paris, America/New_York)
    session_enabled: bool = True
    session_timezone: str = "Europe/Paris"
    session_start: str = "09:00"
    session_end: str = "18:00"

    # Limites par trade / session / jour
    max_risk_usd: float = 100.0
    max_open_positions: int = 3
    max_trades_per_session: int = 5
    default_quantity: float = 1.0
    max_quantity: float = 2.0

    # Perte journalière max (% du capital paper)
    paper_balance: float = 2000.0
    max_daily_loss_pct: float = 3.0

    # Paychek.pro Firebase (web API key — public côté client)
    paychek_firebase_api_key: str = "AIzaSyB_hs_XTxovKaTPz4SQ8cYGSlGmjue3JqY"
    paychek_signup_url: str = "https://paychek.pro/"


settings = Settings()
