"""
Trader API — unified facade for the GUI backend to interact with the trading engine.

Re-exports core functions from `gold_trader.py` and keeps GUI-facing runtime
controls centralized in one import surface.
"""

from __future__ import annotations

from typing import Optional

import bridge.gold_trader as _gold_trader

# ── Core runtime exports (delegated to gold_trader) ──────────────────

from bridge.gold_trader import (
    DAEMON_LOG,
    get_price,
    get_price_truth,
    load_state,
    get_agent_direction,
    get_technical_trend_bias,
    is_mt5_running,
    restart_mt5,
    trigger_panic_close_and_block,
    set_strategy_override,
    reset_signal_generator,
    get_signal_generator_status,
)

# ── GUI runtime control helpers ─────────────────────────────────────


def preload_runtime_bindings() -> None:
    """Verify pipeline runtime bindings are active (no legacy generator pre-warm)."""
    try:
        get_signal_generator_status()
    except Exception:
        pass


def set_auto_select_enabled(enabled: bool) -> None:
    """Enable/disable market-driven strategy auto selection."""
    _gold_trader._AUTO_SELECT_ENABLED = bool(enabled)


def clear_strategy_cache() -> None:
    """Clear cached generators so the next access reloads the runtime."""
    _gold_trader._STRATEGY_CACHE.clear()


def warm_signal_generator(strategy_type: str = "") -> dict:
    """Apply strategy override and return runtime status (pipeline manages signal generation)."""
    if strategy_type:
        _gold_trader._MANUAL_STRATEGY_OVERRIDE = strategy_type
        set_strategy_override(strategy_type)
    return get_signal_generator_status()
