import os
from typing import List


def env_flag(name: str, default: bool = False) -> bool:
    raw = os.getenv(name)
    if raw is None:
        return bool(default)
    return str(raw).strip().lower() not in ("0", "false", "no", "off", "")


# When false (default), keep logs minimal and high-signal.
# Set TEGPT_VERBOSE_LOGS=true to restore detailed tracing.
TEGPT_VERBOSE_LOGS = env_flag("TEGPT_VERBOSE_LOGS", False)

# Trading limits (kept local to trading/order logic)
MAX_POSITION_SIZE = float(os.getenv("MAX_POSITION_SIZE", "100000"))
MIN_PRICE_VALIDATION = float(os.getenv("MIN_PRICE_VALIDATION", "0.01"))

# Timeframe configuration for Zerodha historical data
# These are the default intervals we fetch per symbol for GPT analysis.
DEFAULT_TIMEFRAMES: List[str] = [
    "5minute",
    "15minute",
    "30minute",
    "day",
    "week",
    "month",
]

# How many most-recent candles we keep per timeframe when building
# the snapshot for GPT. Kept small to control token usage.
MAX_CANDLES_PER_TIMEFRAME = int(os.getenv("TEGPT_MAX_CANDLES_PER_TF", "50"))
