"""题目生成模型."""

from typing import Literal

from pydantic import BaseModel, Field

from .action_state import ActionState

Difficulty = Literal["easy", "medium", "hard"]
QuestionType = Literal[
    "single_choice",
    "multi_choice",
    "fill_blank",
    "short_answer",
    "essay",
]


class GenerateQuestionRequest(BaseModel):
    """题目生成请求."""

    prompt: str = Field(..., min_length=1, max_length=2000)
    subject: str = Field(..., max_length=50)
    difficulty: Difficulty = "medium"
    grade: str | None = Field(None, max_length=20)
    knowledge_point_ids: list[str] = Field(default_factory=list, max_length=20)
    question_type: QuestionType = "short_answer"
    count: int = Field(1, ge=1, le=10)


class GeneratedQuestionData(BaseModel):
    """生成的题目数据（含降级标记）."""

    question: str
    answer: str
    explanation: str
    question_type: str = "short_answer"
    difficulty: str = "medium"
    knowledge_point_ids: list[str] = []
    evaluation_score: float | None = None
    degraded: bool = False
    degraded_reason: str = ""


class GeneratedQuestionResponse(ActionState[GeneratedQuestionData]):
    """题目生成响应信封."""
