"""
存储类型定义
定义存储后端和配置相关类型
"""
from enum import Enum
from typing import Optional, Dict, Any
from dataclasses import dataclass


class StorageBackend(Enum):
    """存储后端类型"""
    LOCAL = "local"  # 本地文件系统存储
    QDRANT = "qdrant"  # Qdrant向量数据库
    REDIS = "redis"  # Redis（预留）
    ELASTICSEARCH = "elasticsearch"  # Elasticsearch（预留）


@dataclass
class StorageConfig:
    """
    存储配置
    统一不同存储后端的配置格式
    """
    backend: StorageBackend
    # 通用配置
    persist_dir: Optional[str] = None
    
    # Qdrant配置
    qdrant_url: Optional[str] = None
    qdrant_api_key: Optional[str] = None
    qdrant_host: str = "localhost"
    qdrant_port: int = 6333
    qdrant_collection_name: str = "default"
    
    # Redis配置（预留）
    redis_host: Optional[str] = None
    redis_port: Optional[int] = None
    redis_db: int = 0
    
    # 其他配置
    extra: Dict[str, Any] = None
    
    def __post_init__(self):
        """初始化后处理"""
        if self.extra is None:
            self.extra = {}
    
    @classmethod
    def for_local(cls, persist_dir: str) -> "StorageConfig":
        """创建本地存储配置"""
        return cls(
            backend=StorageBackend.LOCAL,
            persist_dir=persist_dir
        )
    
    @classmethod
    def for_qdrant(
        cls,
        collection_name: str = "default",
        url: Optional[str] = None,
        api_key: Optional[str] = None,
        host: str = "localhost",
        port: int = 6333
    ) -> "StorageConfig":
        """创建Qdrant存储配置"""
        return cls(
            backend=StorageBackend.QDRANT,
            qdrant_url=url,
            qdrant_api_key=api_key,
            qdrant_host=host,
            qdrant_port=port,
            qdrant_collection_name=collection_name
        )
