from typing import List, Optional
from pydantic import BaseModel, Field
from datetime import datetime
from bson import ObjectId

from .answer_item import AnswerItemEntity
from .base import PyObjectId


class UserAnswerEntity(BaseModel):
    id: Optional[PyObjectId] = Field(default=None, alias="_id")
    session_id: Optional[str]
    quiz_id: str
    user_id: str
    answered_at: datetime
    answers: List[AnswerItemEntity]
    total_score: int
    total_correct: int

    class ConfigDict:
        populate_by_name = True
        arbitrary_types_allowed = True
        json_encoders = {ObjectId: str}
