"""Base extractor class for exfil-kit."""
from typing import Any, Dict, Optional
from loguru import logger
from tenacity import retry, stop_after_attempt, wait_exponential

class BaseExtractor:
    """Base class for all extractors."""
    
    def __init__(
        self,
        retries: int = 3,
        timeout: int = 30,
        proxy: Optional[str] = None,
        headers: Optional[Dict[str, str]] = None
    ):
        """Initialize the extractor.
        
        Args:
            retries: Number of retry attempts for failed extractions
            timeout: Request timeout in seconds
            proxy: Optional proxy URL (e.g., "http://user:pass@host:port")
            headers: Optional custom headers
        """
        self.retries = retries
        self.timeout = timeout
        self.proxy = proxy
        self.headers = headers or {}
        logger.info(f"Initialized {self.__class__.__name__}")
    
    @retry(
        stop=stop_after_attempt(3),
        wait=wait_exponential(multiplier=1, min=4, max=10)
    )
    def extract(self, url: str) -> Dict[str, Any]:
        """Extract data from a URL.
        
        Args:
            url: Target URL to extract data from
            
        Returns:
            Dict containing extracted data
            
        Raises:
            NotImplementedError: This base method must be overridden
        """
        raise NotImplementedError("Subclasses must implement extract()")
    
    def _validate_url(self, url: str) -> bool:
        """Validate URL format.
        
        Args:
            url: URL to validate
            
        Returns:
            bool: True if valid, False otherwise
        """
        return url.startswith(("http://", "https://"))
    
    def close(self) -> None:
        """Cleanup any resources."""
        pass