# retoor <retoor@molodetz.nl>

from __future__ import annotations

from typing import Any, Optional

from devplacepy.schemas.base import _Out
from devplacepy.schemas.content import CommentItemOut, UserOut


class QuizOptionOut(_Out):
    uid: str = ""
    position: int = 0
    label: str = ""
    is_correct: Optional[bool] = None
    match_value: Optional[str] = None


class QuizAnswerOut(_Out):
    uid: str = ""
    question_uid: str = ""
    position: int = 0
    answer_text: str = ""
    option_uids: list[str] = []
    answered: bool = False
    answered_at: str = ""
    is_correct: bool = False
    awarded_points: float = 0.0
    feedback: str = ""
    graded_by: str = ""
    confidence: float = 0.0


class QuizQuestionOut(_Out):
    uid: str = ""
    quiz_uid: str = ""
    position: int = 0
    kind: str = ""
    kind_label: str = ""
    prompt: str = ""
    explanation: str = ""
    points: int = 1
    media_attachment_uid: str = ""
    case_sensitive: bool = False
    options: list[QuizOptionOut] = []
    option_count: int = 0
    match_choices: list[str] = []
    correct_boolean: Optional[bool] = None
    expected_answer: Optional[str] = None
    grading_criteria: Optional[str] = None
    numeric_value: Optional[float] = None
    numeric_tolerance: Optional[float] = None
    answer: Optional[QuizAnswerOut] = None


class QuizOut(_Out):
    uid: str = ""
    slug: str = ""
    url: str = ""
    title: str = ""
    description: str = ""
    status: str = "draft"
    published_at: str = ""
    shuffle_questions: bool = False
    shuffle_options: bool = False
    reveal_answers: bool = False
    allow_review: bool = True
    time_limit_seconds: int = 0
    pass_percent: int = 0
    question_count: int = 0
    total_points: int = 0
    attempt_count: int = 0
    stars: int = 0
    created_at: str = ""
    author: Optional[UserOut] = None
    viewer_owns: bool = False
    viewer_is_admin: bool = False
    viewer_can_edit: bool = False
    viewer_can_play: bool = False
    viewer_state: str = "todo"
    validation_errors: list[str] = []


class QuizDetailOut(_Out):
    maturity: Optional[str] = None
    quiz: QuizOut = QuizOut()
    questions: list[QuizQuestionOut] = []
    comments: list[CommentItemOut] = []
    attachments: list[Any] = []
    reactions: dict = {}
    bookmarked: bool = False
    star_count: int = 0
    my_vote: int = 0
    leaderboard: list[Any] = []
    viewer_state: str = "todo"
    viewer_attempt_uid: str = ""


class QuizListItemOut(_Out):
    uid: str = ""
    slug: str = ""
    url: str = ""
    title: str = ""
    description: str = ""
    status: str = "published"
    created_at: str = ""
    time_ago: str = ""
    author: Optional[UserOut] = None
    question_count: int = 0
    total_points: int = 0
    attempt_count: int = 0
    time_limit_seconds: int = 0
    pass_percent: int = 0
    stars: int = 0
    my_vote: int = 0
    comment_count: int = 0
    bookmarked: bool = False
    reactions: dict = {}
    recent_comments: list[CommentItemOut] = []
    viewer_state: str = "todo"
    viewer_best_percent: float = 0.0
    viewer_best_points: float = 0.0
    viewer_attempt_uid: str = ""


class QuizScoreboardEntryOut(_Out):
    rank: int = 0
    user: Optional[UserOut] = None
    total_points: float = 0.0
    quizzes_completed: int = 0
    avg_percent: float = 0.0
    perfect_count: int = 0


class QuizProgressOut(_Out):
    completed: int = 0
    todo: int = 0
    avg_percent: float = 0.0
    total_points: float = 0.0
    rank: int = 0
    perfect_count: int = 0


class QuizScoreboardOut(_Out):
    scoreboard: list[QuizScoreboardEntryOut] = []
    viewer_standing: Optional[QuizScoreboardEntryOut] = None
    limit: int = 0


class QuizzesOut(_Out):
    quizzes: list[QuizListItemOut] = []
    search: str = ""
    filter: str = "all"
    counts: dict = {}
    pagination: dict = {}
    scoreboard: list[QuizScoreboardEntryOut] = []
    viewer_standing: Optional[QuizScoreboardEntryOut] = None
    viewer_progress: QuizProgressOut = QuizProgressOut()
    viewer_can_create: bool = False


class QuizAttemptOut(_Out):
    uid: str = ""
    quiz_uid: str = ""
    quiz_slug: str = ""
    quiz_title: str = ""
    user_uid: str = ""
    status: str = ""
    started_at: str = ""
    expires_at: str = ""
    completed_at: str = ""
    remaining_seconds: int = 0
    answered_count: int = 0
    question_count: int = 0
    score_points: float = 0.0
    max_points: int = 0
    score_percent: float = 0.0
    passed: bool = False
    pass_percent: int = 0
    allow_review: bool = True
    questions: list[QuizQuestionOut] = []


class QuizAttemptPageOut(_Out):
    quiz: QuizOut = QuizOut()
    attempt: QuizAttemptOut = QuizAttemptOut()
    answer_max_chars: int = 0
    quiz_error: Optional[str] = None


class QuizResultOut(_Out):
    quiz: QuizOut = QuizOut()
    attempt: QuizAttemptOut = QuizAttemptOut()
    review: list[QuizQuestionOut] = []
    fallback_count: int = 0


class QuizAnswerResultOut(_Out):
    ok: bool = True
    answer: QuizAnswerOut = QuizAnswerOut()
    attempt: QuizAttemptOut = QuizAttemptOut()


class QuizLeaderboardEntryOut(_Out):
    rank: int = 0
    user: Optional[UserOut] = None
    score_points: float = 0.0
    score_percent: float = 0.0
    passed: bool = False
    completed_at: str = ""


class QuizLeaderboardOut(_Out):
    quiz_uid: str = ""
    entries: list[QuizLeaderboardEntryOut] = []


class QuizDocumentOut(_Out):
    title: str = ""
    description: str = ""
    settings: dict = {}
    questions: list[Any] = []


class QuizBuilderOut(_Out):
    quiz: QuizOut = QuizOut()
    questions: list[QuizQuestionOut] = []
    kinds: list[Any] = []
    validation_errors: list[str] = []
    quiz_error: Optional[str] = None


class QuizFormPageOut(_Out):
    viewer_can_create: bool = False
