"""Factory for creating exchange adapters."""

from typing import Dict, Any, Type
from .interface import ExchangeAdapter
from .kraken import KrakenAdapter


class AdapterFactory:
    """Factory for creating exchange adapters.
    
    Usage:
        adapter = AdapterFactory.create('kraken', config)
    """
    
    _adapters: Dict[str, Type[ExchangeAdapter]] = {
        'kraken': KrakenAdapter,
        # 'binance': BinanceAdapter,  # TODO: Implement
        # 'coinbase': CoinbaseAdapter,  # TODO: Implement
    }
    
    @classmethod
    def register(cls, name: str, adapter_class: Type[ExchangeAdapter]) -> None:
        """Register a new adapter type.
        
        Args:
            name: Adapter name (lowercase)
            adapter_class: Adapter class
        """
        cls._adapters[name.lower()] = adapter_class
    
    @classmethod
    def create(cls, name: str, config: Dict[str, Any]) -> ExchangeAdapter:
        """Create an exchange adapter.
        
        Args:
            name: Exchange name (e.g., 'kraken')
            config: Adapter configuration
            
        Returns:
            Initialized adapter instance
            
        Raises:
            ValueError: If adapter type not found
        """
        adapter_class = cls._adapters.get(name.lower())
        if not adapter_class:
            available = ', '.join(cls._adapters.keys())
            raise ValueError(
                f"Unknown adapter: {name}. Available: {available}"
            )
        
        return adapter_class(config)
    
    @classmethod
    def list_available(cls) -> list:
        """List available adapter types.
        
        Returns:
            List of adapter names
        """
        return list(cls._adapters.keys())
