"""Base class for cache handlers."""

from abc import ABC, abstractmethod
from pathlib import Path
from typing import Optional
import pandas as pd


class BaseCache(ABC):
    """
    Abstract base class for all cache handlers.
    
    All cache implementations should inherit from this class and implement
    the save and load methods.
    """
    
    def __init__(self, cache_dir: str = "./cache"):
        """
        Initialize the cache handler.
        
        Args:
            cache_dir: Directory where cache files will be stored
        """
        self.cache_dir = Path(cache_dir)
        self.cache_dir.mkdir(parents=True, exist_ok=True)
    
    @abstractmethod
    def save(self, data: pd.DataFrame, filename: str) -> None:
        """
        Save data to cache.
        
        Args:
            data: The DataFrame to save
            filename: The name of the file (without extension)
            
        Raises:
            NotImplementedError: If not implemented by subclass
        """
        raise NotImplementedError("Subclasses must implement save method")
    
    @abstractmethod
    def load(self, filename: str) -> pd.DataFrame:
        """
        Load data from cache.
        
        Args:
            filename: The name of the file to load (without extension)
            
        Returns:
            pd.DataFrame: The loaded DataFrame
            
        Raises:
            NotImplementedError: If not implemented by subclass
        """
        raise NotImplementedError("Subclasses must implement load method")
    
    def exists(self, filename: str) -> bool:
        """
        Check if a cache file exists.
        
        Args:
            filename: The name of the file to check
            
        Returns:
            bool: True if file exists, False otherwise
        """
        return False
    
    def delete(self, filename: str) -> None:
        """
        Delete a cache file.
        
        Args:
            filename: The name of the file to delete
        """
        pass
    
    def list_files(self) -> list:
        """
        List all cache files.
        
        Returns:
            list: List of cache file names
        """
        return []
