from __future__ import annotations

from dataclasses import dataclass
from decimal import Decimal
from pathlib import Path
import os


@dataclass(frozen=True)
class LivePreviewSettings:
    strategy_id: str = "candidate_v76_hl_confirmed_squeeze_hybrid"
    wallet_equity_usdc: Decimal = Decimal("500")
    risk_per_trade_pct: Decimal = Decimal("0.25")
    max_parallel_positions: int = 1
    leverage: Decimal = Decimal("2")
    margin_mode: str = "isolated"
    max_daily_loss_pct: Decimal = Decimal("0.75")
    max_weekly_loss_pct: Decimal = Decimal("2.0")
    max_position_margin_pct: Decimal = Decimal("8")
    max_position_notional_pct: Decimal = Decimal("20")
    min_order_notional_usd: Decimal = Decimal("10")
    live_trading_allowed: bool = False
    live_confirmation: str | None = None
    runtime_dir: Path = Path.home() / ".local/state/CryptoTradingBot/v76_live_preview"

    @classmethod
    def from_env(cls) -> "LivePreviewSettings":
        return cls(
            live_trading_allowed=os.getenv("CTB_LIVE_TRADING_ALLOWED", "").lower() == "true",
            live_confirmation=os.getenv("CTB_LIVE_CONFIRMATION"),
        )
