"""
Symbol normalization between exchanges.
"""
from config import SYMBOL_MAP, REVERSE_SYMBOL_MAP


def to_exchange_symbol(canonical: str, exchange: str) -> str | None:
    """
    Convert a canonical symbol (e.g., "BTC") to exchange-specific format.

    Args:
        canonical: The canonical symbol (e.g., "BTC", "ETH")
        exchange: The exchange name (e.g., "binance", "coinbase")

    Returns:
        Exchange-specific symbol (e.g., "BTCUSDT", "BTC-USD") or None if not found.
    """
    exchange_map = SYMBOL_MAP.get(exchange)
    if not exchange_map:
        return None
    return exchange_map.get(canonical)


def to_canonical_symbol(exchange_symbol: str, exchange: str) -> str | None:
    """
    Convert an exchange-specific symbol to canonical format.

    Args:
        exchange_symbol: The exchange-specific symbol (e.g., "BTCUSDT", "BTC-USD")
        exchange: The exchange name

    Returns:
        Canonical symbol (e.g., "BTC") or None if not found.
    """
    reverse_map = REVERSE_SYMBOL_MAP.get(exchange)
    if not reverse_map:
        return None
    return reverse_map.get(exchange_symbol)


def get_all_exchange_symbols(exchange: str) -> list[str]:
    """Get all configured symbols for an exchange in exchange-specific format."""
    exchange_map = SYMBOL_MAP.get(exchange, {})
    return list(exchange_map.values())


def get_all_canonical_symbols() -> list[str]:
    """Get all canonical symbols configured in the system."""
    # Use binance as reference since all exchanges should have same canonical symbols
    return list(SYMBOL_MAP.get("binance", {}).keys())
