from typing import Optional
from pydantic import BaseModel, Field
from datetime import datetime
from .base import PyObjectId
from .question_item_entity import QuestionItemEntity


class QuizEntity(BaseModel):
    id: Optional[PyObjectId] = Field(default=None, alias="_id")
    author_id: Optional[str] = None
    subject_id: str
    title: str
    description: Optional[str] = None
    is_public: bool = False
    date: datetime
    total_quiz: int = 0
    limit_duration: Optional[int] = 0  # in
    total_user_playing: int = 0
    question_listings: Optional[list[QuestionItemEntity]] = []

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