# app/tools/dzengi_probe/config.py

from __future__ import annotations

import os
from dataclasses import dataclass
from pathlib import Path

from dotenv import load_dotenv


@dataclass(frozen=True)
class DzengiProbeConfig:
    base_url: str
    ws_url: str
    api_version: str
    symbol: str
    symbol_file_name: str
    interval: str
    depth_limit: str
    agg_trades_limit: str
    timeout_seconds: float
    output_dir: Path


def load_config() -> DzengiProbeConfig:
    load_dotenv("app/.env")

    base_url = os.getenv("EXCHANGE_BASE_URL", "").rstrip("/")
    ws_url = os.getenv("EXCHANGE_WS_URL", "").rstrip("/")

    if not base_url:
        raise RuntimeError("EXCHANGE_BASE_URL is empty.")

    symbol = os.getenv("PROBE_SYMBOL", "BTC/USD_LEVERAGE")
    symbol_file_name = symbol.replace("/", "_")

    return DzengiProbeConfig(
        base_url=base_url,
        ws_url=ws_url,
        api_version=os.getenv("PROBE_API_VERSION", "v1"),
        symbol=symbol,
        symbol_file_name=symbol_file_name,
        interval=os.getenv("PROBE_KLINE_INTERVAL", "1m"),
        depth_limit=os.getenv("PROBE_DEPTH_LIMIT", "20"),
        agg_trades_limit=os.getenv("PROBE_AGG_TRADES_LIMIT", "20"),
        timeout_seconds=float(os.getenv("EXCHANGE_TIMEOUT_SEC", "10")),
        output_dir=Path("app/tools/dzengi_probe/runtime_samples"),
    )