from datetime import datetime
from pydantic import BaseModel, Field
from typing import List, Optional


# ------------------------------
# 请求模型（前端传参校验）
# ------------------------------
class SensitiveCreateRequest(BaseModel):
    """创建敏感信息记录请求模型"""
    name: str = Field(..., max_length=255, description="敏感词内容（必填）")


class SensitiveUpdateRequest(BaseModel):
    """更新敏感信息记录请求模型"""
    name: Optional[str] = Field(None, max_length=255, description="敏感词内容（可选修改）")


# ------------------------------
# 响应模型（后端返回数据）
# ------------------------------
class SensitiveResponse(BaseModel):
    """敏感信息单条记录响应模型"""
    id: int = Field(..., description="主键ID")
    name: str = Field(..., description="敏感词内容")
    created_at: datetime = Field(..., description="记录创建时间")
    updated_at: datetime = Field(..., description="记录更新时间")

    # 支持从数据库查询结果（字典/对象）自动转换
    model_config = {"from_attributes": True}


class SensitiveListResponse(BaseModel):
    """敏感信息分页列表响应模型（新增）"""
    total: int = Field(..., description="敏感词总记录数")
    sensitives: List[SensitiveResponse] = Field(..., description="当前页敏感词列表")

    model_config = {"from_attributes": True}