"""
AkDevz AI Market Intelligence — Base Broker Interface
Defines the institutional interface for genuine market data providers
and authorized execution brokers.
"""
from abc import ABC, abstractmethod
from typing import Dict, Any, List, Optional

class BaseBrokerAdapter(ABC):
    def __init__(self, provider_code: str, credentials: Dict[str, Any]):
        self.provider_code = provider_code
        self.credentials = credentials
        self.is_authenticated = False

    @abstractmethod
    def authenticate(self) -> bool:
        """Authenticates with the broker using OAuth2 or TOTP/API Key."""
        pass

    @abstractmethod
    def get_quotes(self, symbols: List[str]) -> Dict[str, Dict[str, Any]]:
        """Retrieves real-time market quotes with price, change, volume, OHLC."""
        pass

    @abstractmethod
    def get_historical_candles(
        self,
        symbol: str,
        resolution: str = "5",
        range_from: str = "",
        range_to: str = ""
    ) -> List[List[Any]]:
        """Retrieves authentic historical candle series."""
        pass

    @abstractmethod
    def get_option_chain(self, symbol: str, strike_count: int = 15) -> Optional[Dict[str, Any]]:
        """Retrieves authentic option chain and strike-wise OI."""
        pass

    @abstractmethod
    def get_funds_and_margin(self) -> Dict[str, Any]:
        """Retrieves authentic user margin, available cash, and used limit."""
        pass

    @abstractmethod
    def get_positions(self) -> List[Dict[str, Any]]:
        """Retrieves authentic open broker positions."""
        pass

    @abstractmethod
    def place_order(self, order_params: Dict[str, Any]) -> Dict[str, Any]:
        """Submits an authorized order to the broker with idempotency."""
        pass

    @abstractmethod
    def modify_order(self, order_id: str, params: Dict[str, Any]) -> Dict[str, Any]:
        """Modifies permitted open protective orders (stop-loss, target)."""
        pass

    @abstractmethod
    def cancel_order(self, order_id: str) -> Dict[str, Any]:
        """Cancels an open order."""
        pass
