"""
Pydantic 数据模型
"""
from typing import Optional, List, Any
from pydantic import BaseModel, Field
from datetime import datetime


# ============ 通用响应 ============

class ApiResponse(BaseModel):
    """统一 API 响应格式"""
    code: int = 0
    message: str = "success"
    data: Any = None


# ============ 候选人相关 ============

class SubmitCandidateResponse(BaseModel):
    """提交候选人信息响应"""
    sessionId: str
    fileId: str


class CreateRoomRequest(BaseModel):
    """创建房间请求"""
    sessionId: Optional[str] = None  # 方案A：可选，由后端生成
    fileId: Optional[str] = None  # 方案A：可选，由工作流收集


class CreateRoomResponse(BaseModel):
    """创建房间响应"""
    roomId: str
    token: str
    appId: str
    userId: str
    sessionId: Optional[str] = None  # 返回给前端用于后续操作
    debugInfo: Optional[Any] = None  # 调试信息（语音模式）


class EndInterviewResponse(BaseModel):
    """结束面试响应"""
    success: bool


class ChatRequest(BaseModel):
    """文本对话请求（模拟语音）"""
    sessionId: str
    message: str
    conversationId: Optional[str] = None


class ChatResponse(BaseModel):
    """文本对话响应"""
    reply: str
    conversationId: str
    debugInfo: Optional[Any] = None  # 调试信息（节点状态、消息列表等）


# ============ 管理后台相关 ============

class CandidateScores(BaseModel):
    """候选人评分"""
    salesSkill: int = Field(0, ge=0, le=100)
    salesMindset: int = Field(0, ge=0, le=100)
    quality: int = Field(0, ge=0, le=100)
    motivation: int = Field(0, ge=0, le=100)
    total: float = Field(0, ge=0, le=100)


class CandidateListItem(BaseModel):
    """候选人列表项"""
    sessionId: str
    name: str
    status: str  # pending, ongoing, completed
    score: Optional[float] = None
    createdAt: str


class CandidateDetail(BaseModel):
    """候选人详情"""
    sessionId: str
    name: str
    resume: Optional[str] = None
    status: str
    currentStage: int = 0
    scores: Optional[CandidateScores] = None
    analysis: Optional[str] = None
    interviewLog: Optional[str] = None
    createdAt: str
    completedAt: Optional[str] = None


class CandidateListResponse(BaseModel):
    """候选人列表响应"""
    list: List[CandidateListItem]
    total: int
    page: int
    pageSize: int
