from typing import Dict, Any, Optional, List
from pydantic import BaseModel, Field, ConfigDict


class BaseAPIRequest(BaseModel):
    """基础API请求模型"""
    provider: str = Field(..., description="API提供商", example="chinaz")
    endpoint: str = Field(..., description="端点名称", example="icp_info")
    params: Dict[str, Any] = Field(default_factory=dict, description="请求参数")
    timeout: Optional[int] = Field(30, description="超时时间(秒)")


class ChinazAPIRequest(BaseModel):
    """站长之家API请求模型"""
    company_name: str = Field(..., description="公司名称", example="百度在线网络技术（北京）有限公司")
    chinaz_ver: Optional[str] = Field("1", description="API版本", example="1")
    timeout: Optional[int] = Field(30, description="超时时间(秒)")


class XiaohongshuNoteRequest(BaseModel):
    """小红书笔记详情请求"""
    note_id: str = Field(..., description="笔记ID", example="68d2c71d000000000e00e9ea")


class JizhiliaoSearchRequest(BaseModel):
    """极致聊指数搜索请求"""
    model_config = ConfigDict(populate_by_name=True)

    keyword: str = Field(..., description="搜索关键词", example="人民日报")
    mode: int = Field(2, description="搜索模式", example=2)
    business_type: int = Field(
        8192,
        alias="BusinessType",
        description="业务类型标识",
        example=8192,
    )
    sub_search_type: int = Field(0, description="子搜索类型", example=0)
    verifycode: Optional[str] = Field("", description="验证码", example="")
    timeout: Optional[int] = Field(30, description="超时时间(秒)")


class APIResponse(BaseModel):
    """API响应模型"""
    success: bool = Field(..., description="请求是否成功")
    data: Dict[str, Any] = Field(..., description="响应数据")
    message: Optional[str] = Field(None, description="响应消息")
    provider: Optional[str] = Field(None, description="API提供商")
    endpoint: Optional[str] = Field(None, description="端点名称")


class APIProviderInfo(BaseModel):
    """API提供商信息"""
    name: str = Field(..., description="提供商名称")
    base_url: str = Field(..., description="基础URL")
    description: Optional[str] = Field(None, description="描述")
    endpoints: List[str] = Field(default_factory=list, description="可用端点")


class APIEndpointInfo(BaseModel):
    """API端点信息"""
    name: str = Field(..., description="端点名称")
    path: str = Field(..., description="请求路径")
    method: str = Field(..., description="HTTP方法")
    description: Optional[str] = Field(None, description="描述")
    required_params: List[str] = Field(default_factory=list, description="必需参数")
    optional_params: List[str] = Field(default_factory=list, description="可选参数")


class APIListResponse(BaseModel):
    """API列表响应"""
    providers: List[APIProviderInfo] = Field(..., description="API提供商列表")
    total_providers: int = Field(..., description="提供商总数")