from pydantic import BaseModel
from typing import Optional
from typing import List,Union

class ReqeustBase(BaseModel):
    action: str

class TextData(BaseModel):
    text: str

class EmbeddingRequest(ReqeustBase):
    data: List[TextData]

class SearchRequest(ReqeustBase):
    query: str
    top_k: int = 20
    meta_only: Optional[bool] = False 

class GetDocumentRequest(ReqeustBase):
    title: str

class GraphFilterRequest(ReqeustBase):
    node_types: Optional[List[str]] = None
    min_degree: Optional[int] = None
    min_community_size: Optional[int] = None
    attributes: Optional[dict] = None

class GraphSearchRequest(ReqeustBase):
    """图谱语义搜索请求参数"""
    query: str
    node_types: Optional[List[str]] = None
    relationship_types: Optional[List[str]] = None
    min_weight: Optional[float] = None
    max_depth: int = 3
    limit: int = 20
    similarity_threshold: float = 0.6

class PathAnalysisRequest(ReqeustBase):
    """节点路径分析请求参数"""
    source: str
    target: str
    max_path_length: int = 3
    algorithm: str = "bidirectional"

class NodeFilterRequest(ReqeustBase):
    """复杂节点过滤请求参数"""
    must: List[dict] = []
    should: List[dict] = []
    must_not: List[dict] = []
    min_score: Optional[float] = None
    

class BasicRequestParameter(BaseModel):
    name: str
    value: Union[str, int, float, bool, List[str], List[int], List[float], List[bool]]  
    
      
class BasicRequest(BaseModel):
    action: str
    id: str
    params: List[BasicRequestParameter]
    
    def get_param(self, name=None, default=None):
        for param in self.params:
            if param.name == name:
                return param.value
        return default
