from pydantic import BaseModel, Field
from typing import List

class ConceptExplanation(BaseModel):
    concept_name: str = Field(..., description="The name of the concept being explained.")
    definition: str = Field(..., description="A clear and concise definition of the concept.")
    analogy: str = Field("", description="An illustrative analogy to simplify understanding.")
    core_principles: List[str] = Field(default_factory=list, description="Key principles or characteristics of the concept.")
    example_use_case: str = Field("", description="A simple, practical example or use case.")
    common_pitfalls: List[str] = Field(default_factory=list, description="Common misunderstandings or pitfalls to avoid.")
    detailed_explanation: str = Field("", description="A comprehensive and in-depth explanation of the concept, including technical details, internal workings, and real-world implementation considerations.")

class ConceptRequest(BaseModel):
    topic: str # e.g., "Kubernetes Pods"
    proficiency_level: str = Field("beginner", description="User's proficiency level: 'beginner', 'intermediate', or 'advanced'")

class ChallengeFeedback(BaseModel):
    assessment: str = Field(..., description="Overall assessment of the user's solution (e.g., 'Correct', 'Partially Correct', 'Needs Improvement').")
    positive_points: List[str] = Field(default_factory=list, description="Aspects of the user's solution that were good or correct.")
    areas_for_improvement: List[str] = Field(default_factory=list, description="Specific areas where the solution could be improved or was incorrect.")
    suggested_next_step: str = Field("", description="A hint or the next logical step for the user to consider.")
    detailed_explanation: str = Field("", description="A more detailed explanation of the concepts involved or the correct solution.")

class ChallengeAttempt(BaseModel):
    challenge_id: str  # Identifier for a predefined challenge/scenario
    user_solution: str # User's textual answer or proposed command/config

class QuizOption(BaseModel):
    id: str  # e.g., "A", "B", "C"
    text: str

class QuizQuestion(BaseModel):
    topic: str = Field(..., description="The topic of the quiz question.")
    question_text: str = Field(..., description="The actual question.")
    question_type: str = Field(..., description="e.g., 'multiple_choice', 'true_false', 'short_answer_explanation'")
    options: List[QuizOption] = Field(default_factory=list, description="Options for multiple choice questions.")
    correct_option_id: str = Field("", description="ID of the correct option for multiple_choice.")
    answer_explanation: str = Field(..., description="Explanation of why the correct answer is correct, or the full answer for short_answer types.")

class QuizRequest(BaseModel):
    topic: str
    difficulty: str = "Intermediate" # Changed default from medium to Intermediate for consistency
    requested_question_type: str = Field("", description="Optional: 'multiple_choice', 'true_false', or 'short_answer_explanation'. If empty string, a type will be chosen randomly.")

# Models for Dynamically Generated Challenges
class GenerateChallengeRequest(BaseModel):
    topic: str = Field(..., description="The DevOps topic for which to generate a challenge (e.g., Kubernetes, Docker, Git).")
    difficulty_hint: str = Field("Intermediate", description="A hint for the desired difficulty level (e.g., Beginner, Intermediate, Advanced).")

class GeneratedChallenge(BaseModel):
    title: str = Field(..., description="A concise and descriptive title for the challenge.")
    topic: str = Field(..., description="The main DevOps topic this challenge relates to.") # Re-iterated from request or inferred by LLM.
    difficulty: str = Field(..., description="Estimated difficulty decided by the LLM (e.g., 'Beginner', 'Intermediate', 'Advanced').")
    description: str = Field(..., description="The detailed problem statement or scenario for the user to solve.")
    evaluation_criteria: str = Field(..., description="Specific criteria an AI tutor should use to evaluate a user's solution to THIS generated challenge. This is generated by the LLM itself.")
    solution_keywords: List[str] = Field(default_factory=list, description="Keywords or commands expected in a good solution.") 

class DynamicChallengeAttempt(BaseModel):
    challenge_title: str = Field(..., description="The title of the dynamically generated challenge.")
    challenge_topic: str = Field(..., description="The topic of the dynamically generated challenge.") # Added topic
    challenge_difficulty: str = Field(..., description="The difficulty of the dynamically generated challenge.") # Added difficulty
    challenge_description: str = Field(..., description="The description of the dynamically generated challenge.")
    challenge_evaluation_criteria: str = Field(..., description="The evaluation criteria for the dynamically generated challenge provided by the challenge generator LLM.")
    challenge_solution_keywords: List[str] = Field(default_factory=list, description="Optional solution keywords for the dynamically generated challenge.") # Added keywords
    user_solution: str = Field(..., description="The user's submitted solution.") 

# Mind Map Models
class MindMapNode(BaseModel):
    id: str = Field(..., description="Unique identifier for the node")
    label: str = Field(..., description="The text label of the node")
    level: int = Field(..., description="Hierarchical level (0 for root)")
    group: str = Field("default", description="Group/category for styling purposes")
    description: str = Field("", description="Additional information about this concept")

class MindMapEdge(BaseModel):
    from_id: str = Field(..., description="Source node ID")
    to_id: str = Field(..., description="Target node ID")
    label: str = Field("", description="Optional relationship description")

class MindMap(BaseModel):
    topic: str = Field(..., description="The main topic of the mind map")
    nodes: List[MindMapNode] = Field(..., description="The nodes/concepts in the mind map")
    edges: List[MindMapEdge] = Field(..., description="The connections between concepts")

class MindMapRequest(BaseModel):
    topic: str = Field(..., description="The DevOps topic to create a mind map for")
    depth: int = Field(2, description="How many levels deep the mind map should go (1-3)")
    focus_area: str = Field("", description="Optional subtopic to emphasize") 