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

# User Models
class UserBase(BaseModel):
    username: str
    email: EmailStr
    role: str = "user"
    full_name: Optional[str] = None

class UserCreate(UserBase):
    password: str

class User(UserBase):
    id: Optional[str] = Field(default=None, alias="_id")
    is_active: bool = True
    created_at: datetime = Field(default_factory=datetime.utcnow)

    class Config:
        populate_by_name = True

class AdminLogin(BaseModel):
    username: str
    password: str

# Question Models
class QuestionBase(BaseModel):
    text: str
    image_url: Optional[str] = None
    options: List[str]
    correct_option: int

class QuestionCreate(QuestionBase):
    pass

class QuestionUpdate(QuestionBase):
    pass

class Question(QuestionBase):
    id: Optional[str] = Field(default=None, alias="_id")

# Assessment/Submission Models
class AnswerKey(BaseModel):
    question_id: str
    selected_option: int

class SubmissionCreate(BaseModel):
    answers: List[AnswerKey]
    time_taken: int

class Submission(BaseModel):
    id: Optional[str] = Field(default=None, alias="_id")
    user_id: str
    answers: List[AnswerKey]
    score: int
    created_at: datetime = Field(default_factory=datetime.utcnow)

class ApprovalData(BaseModel):
    user_id: str
    approved: bool
