"""备课工作流模型."""

from typing import Literal

from pydantic import BaseModel, Field

from .action_state import ActionState
from .question import GeneratedQuestionData

WorkflowStatus = Literal[
    "pending",
    "analyzing",
    "generating",
    "pending_review",
    "persisted",
    "failed",
]


class LessonPreparationRequest(BaseModel):
    """备课工作流启动请求."""

    class_id: str
    subject_id: str
    topic: str = Field(..., max_length=500)
    target_difficulty: Literal["easy", "medium", "hard"] = "medium"
    question_count: int = Field(5, ge=1, le=20)


class LessonPreparationData(BaseModel):
    """备课工作流启动响应数据."""

    workflow_id: str
    status: WorkflowStatus
    estimated_completion_seconds: int = 60
    degraded: bool = False
    degraded_reason: str = ""


class LessonPreparationResponse(ActionState[LessonPreparationData]):
    """备课工作流启动响应信封."""


class WorkflowStatusData(BaseModel):
    """工作流状态查询响应数据."""

    workflow_id: str
    status: WorkflowStatus
    questions: list[GeneratedQuestionData] = []
    error: str | None = None
    degraded: bool = False
    degraded_reason: str = ""


class WorkflowStatusResponse(ActionState[WorkflowStatusData]):
    """工作流状态查询响应信封."""


class ConfirmRequest(BaseModel):
    """教师确认入库请求."""

    modifications: dict[str, str] | None = None  # question_id → 修改后内容


class ConfirmResultData(BaseModel):
    """确认入库结果数据."""

    success: bool
    persisted_question_ids: list[str] = []


class ConfirmResultResponse(ActionState[ConfirmResultData]):
    """确认入库响应信封."""
