# coding: utf-8

"""
    Moodle Webservice API

    Auto-generated OpenAPI spec for Moodle's Webservice API.

    The version of the OpenAPI document: 5.0.3 (Build: 20251006)
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from poodle_async_full.models.core_block_get_course_blocks_response_blocks_inner_contents_files_inner import CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModQuizGetQuizzesByCoursesResponseQuizzesInner(BaseModel):
    """
    ModQuizGetQuizzesByCoursesResponseQuizzesInner
    """ # noqa: E501
    allowofflineattempts: Optional[StrictInt] = Field(default=None, description="Whether to allow the quiz to be attempted                                                                             offline in the mobile app")
    attemptonlast: Optional[StrictInt] = Field(default=None, description="Whether subsequent attempts start from the answer                                                                     to the previous attempt (1) or start blank (0).")
    attempts: Optional[StrictInt] = Field(default=None, description="The maximum number of attempts a student is allowed.")
    autosaveperiod: Optional[StrictInt] = Field(default=None, description="Auto-save delay")
    browsersecurity: Optional[StrictStr] = Field(default=None, description="Restriciton on the browser the student must                                                                     use. E.g. 'securewindow'.")
    canredoquestions: Optional[StrictInt] = Field(default=None, description="Allows students to redo any completed question                                                                         within a quiz attempt.")
    completionattemptsexhausted: Optional[StrictInt] = Field(default=None, description="Mark quiz complete when the student has                                                                                 exhausted the maximum number of attempts")
    completionpass: Optional[StrictInt] = Field(default=None, description="Whether to require passing grade")
    course: Optional[StrictInt] = Field(description="Course id")
    coursemodule: Optional[StrictInt] = Field(description="Course module id")
    decimalpoints: Optional[StrictInt] = Field(default=None, description="Number of decimal points to use when displaying                                                                     grades.")
    delay1: Optional[StrictInt] = Field(default=None, description="Delay that must be left between the first and second attempt,                                                             in seconds.")
    delay2: Optional[StrictInt] = Field(default=None, description="Delay that must be left between the second and subsequent                                                             attempt, in seconds.")
    graceperiod: Optional[StrictInt] = Field(default=None, description="The amount of time (in seconds) after the time limit                                                                 runs out during which attempts can still be submitted,                                                                 if overduehandling is set to allow it.")
    grade: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The total that the quiz overall grade is scaled to be                                                             out of.")
    grademethod: Optional[StrictInt] = Field(default=None, description="One of the values QUIZ_GRADEHIGHEST, QUIZ_GRADEAVERAGE,                                                                     QUIZ_ATTEMPTFIRST or QUIZ_ATTEMPTLAST.")
    groupingid: Optional[StrictInt] = Field(default=None, description="Group id")
    groupmode: Optional[StrictInt] = Field(default=None, description="Group mode")
    hasfeedback: Optional[StrictInt] = Field(default=None, description="Whether the quiz has any non-blank feedback text")
    hasquestions: Optional[StrictInt] = Field(default=None, description="Whether the quiz has questions")
    id: Optional[StrictInt] = Field(description="Activity instance id")
    intro: Optional[StrictStr] = Field(default=None, description="Activity introduction")
    introfiles: Optional[List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner]] = Field(default=None, description="Files in the introduction")
    introformat: Optional[StrictInt] = Field(default=None, description="intro format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    lang: Optional[StrictStr] = Field(default=None, description="Forced activity language")
    name: Optional[StrictStr] = Field(description="Activity name")
    navmethod: Optional[StrictStr] = Field(default=None, description="Any constraints on how the user is allowed to navigate                                                                 around the quiz. Currently recognised values are                                                                 'free' and 'seq'.")
    overduehandling: Optional[StrictStr] = Field(default=None, description="The method used to handle overdue attempts.                                                                     'autosubmit', 'graceperiod' or 'autoabandon'.")
    password: Optional[StrictStr] = Field(default=None, description="A password that the student must enter before starting or                                                                 continuing a quiz attempt.")
    precreateattempts: Optional[StrictInt] = Field(default=None, description="Whether attempt pre-creation is enabled")
    preferredbehaviour: Optional[StrictStr] = Field(default=None, description="The behaviour to ask questions to use.")
    questiondecimalpoints: Optional[StrictInt] = Field(default=None, description="Number of decimal points to use when                                                                             displaying question grades.                                                                             (-1 means use decimalpoints.)")
    questionsperpage: Optional[StrictInt] = Field(default=None, description="How often to insert a page break when editing                                                                         the quiz, or when shuffling the question order.")
    reviewattempt: Optional[StrictInt] = Field(default=None, description="Whether users are allowed to review their quiz                                                                     attempts at various times. This is a bit field, decoded by the                                                                     \\mod_quiz\\question\\display_options class. It is formed by ORing                                                                     together the constants defined there.")
    reviewcorrectness: Optional[StrictInt] = Field(default=None, description="Whether users are allowed to review their quiz                                                        attempts at various times.A bit field, like reviewattempt.")
    reviewgeneralfeedback: Optional[StrictInt] = Field(default=None, description="Whether users are allowed to review their                                                                             quiz attempts at various times. A bit field, like                                                                             reviewattempt.")
    reviewmarks: Optional[StrictInt] = Field(default=None, description="Whether users are allowed to review their quiz attempts                                                                 at various times. A bit field, like reviewattempt.")
    reviewmaxmarks: Optional[StrictInt] = Field(default=None, description="Whether users are allowed to review their quiz                                                   attempts at various times. A bit field, like reviewattempt.")
    reviewoverallfeedback: Optional[StrictInt] = Field(default=None, description="Whether users are allowed to review their quiz                                                                             attempts at various times. A bit field, like                                                                             reviewattempt.")
    reviewrightanswer: Optional[StrictInt] = Field(default=None, description="Whether users are allowed to review their quiz                                                                         attempts at various times. A bit field, like                                                                         reviewattempt.")
    reviewspecificfeedback: Optional[StrictInt] = Field(default=None, description="Whether users are allowed to review their                                                                             quiz attempts at various times. A bit field, like                                                                             reviewattempt.")
    section: Optional[StrictInt] = Field(default=None, description="Course section id")
    showblocks: Optional[StrictInt] = Field(default=None, description="Whether blocks should be shown on the attempt.php and                                                                 review.php pages.")
    showuserpicture: Optional[StrictInt] = Field(default=None, description="Option to show the user's picture during the                                                                     attempt and on the review page.")
    shuffleanswers: Optional[StrictInt] = Field(default=None, description="Whether the parts of the question should be shuffled,                                                                     in those question types that support it.")
    subnet: Optional[StrictStr] = Field(default=None, description="Used to restrict the IP addresses from which this quiz can                                                             be attempted. The format is as requried by the address_in_subnet                                                             function.")
    sumgrades: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The total of all the question instance maxmarks.")
    timeclose: Optional[StrictInt] = Field(default=None, description="The time when this quiz closes. (0 = no restriction.)")
    timecreated: Optional[StrictInt] = Field(default=None, description="The time when the quiz was added to the course.")
    timelimit: Optional[StrictInt] = Field(default=None, description="The time limit for quiz attempts, in seconds.")
    timemodified: Optional[StrictInt] = Field(default=None, description="Last modified time.")
    timeopen: Optional[StrictInt] = Field(default=None, description="The time when this quiz opens. (0 = no restriction.)")
    visible: Optional[StrictBool] = Field(default=None, description="Visible")
    __properties: ClassVar[List[str]] = ["allowofflineattempts", "attemptonlast", "attempts", "autosaveperiod", "browsersecurity", "canredoquestions", "completionattemptsexhausted", "completionpass", "course", "coursemodule", "decimalpoints", "delay1", "delay2", "graceperiod", "grade", "grademethod", "groupingid", "groupmode", "hasfeedback", "hasquestions", "id", "intro", "introfiles", "introformat", "lang", "name", "navmethod", "overduehandling", "password", "precreateattempts", "preferredbehaviour", "questiondecimalpoints", "questionsperpage", "reviewattempt", "reviewcorrectness", "reviewgeneralfeedback", "reviewmarks", "reviewmaxmarks", "reviewoverallfeedback", "reviewrightanswer", "reviewspecificfeedback", "section", "showblocks", "showuserpicture", "shuffleanswers", "subnet", "sumgrades", "timeclose", "timecreated", "timelimit", "timemodified", "timeopen", "visible"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of ModQuizGetQuizzesByCoursesResponseQuizzesInner from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in introfiles (list)
        _items = []
        if self.introfiles:
            for _item_introfiles in self.introfiles:
                if _item_introfiles:
                    _items.append(_item_introfiles.to_dict())
            _dict['introfiles'] = _items
        # set to None if allowofflineattempts (nullable) is None
        # and model_fields_set contains the field
        if self.allowofflineattempts is None and "allowofflineattempts" in self.model_fields_set:
            _dict['allowofflineattempts'] = None

        # set to None if attemptonlast (nullable) is None
        # and model_fields_set contains the field
        if self.attemptonlast is None and "attemptonlast" in self.model_fields_set:
            _dict['attemptonlast'] = None

        # set to None if attempts (nullable) is None
        # and model_fields_set contains the field
        if self.attempts is None and "attempts" in self.model_fields_set:
            _dict['attempts'] = None

        # set to None if autosaveperiod (nullable) is None
        # and model_fields_set contains the field
        if self.autosaveperiod is None and "autosaveperiod" in self.model_fields_set:
            _dict['autosaveperiod'] = None

        # set to None if browsersecurity (nullable) is None
        # and model_fields_set contains the field
        if self.browsersecurity is None and "browsersecurity" in self.model_fields_set:
            _dict['browsersecurity'] = None

        # set to None if canredoquestions (nullable) is None
        # and model_fields_set contains the field
        if self.canredoquestions is None and "canredoquestions" in self.model_fields_set:
            _dict['canredoquestions'] = None

        # set to None if completionattemptsexhausted (nullable) is None
        # and model_fields_set contains the field
        if self.completionattemptsexhausted is None and "completionattemptsexhausted" in self.model_fields_set:
            _dict['completionattemptsexhausted'] = None

        # set to None if completionpass (nullable) is None
        # and model_fields_set contains the field
        if self.completionpass is None and "completionpass" in self.model_fields_set:
            _dict['completionpass'] = None

        # set to None if course (nullable) is None
        # and model_fields_set contains the field
        if self.course is None and "course" in self.model_fields_set:
            _dict['course'] = None

        # set to None if coursemodule (nullable) is None
        # and model_fields_set contains the field
        if self.coursemodule is None and "coursemodule" in self.model_fields_set:
            _dict['coursemodule'] = None

        # set to None if decimalpoints (nullable) is None
        # and model_fields_set contains the field
        if self.decimalpoints is None and "decimalpoints" in self.model_fields_set:
            _dict['decimalpoints'] = None

        # set to None if delay1 (nullable) is None
        # and model_fields_set contains the field
        if self.delay1 is None and "delay1" in self.model_fields_set:
            _dict['delay1'] = None

        # set to None if delay2 (nullable) is None
        # and model_fields_set contains the field
        if self.delay2 is None and "delay2" in self.model_fields_set:
            _dict['delay2'] = None

        # set to None if graceperiod (nullable) is None
        # and model_fields_set contains the field
        if self.graceperiod is None and "graceperiod" in self.model_fields_set:
            _dict['graceperiod'] = None

        # set to None if grade (nullable) is None
        # and model_fields_set contains the field
        if self.grade is None and "grade" in self.model_fields_set:
            _dict['grade'] = None

        # set to None if grademethod (nullable) is None
        # and model_fields_set contains the field
        if self.grademethod is None and "grademethod" in self.model_fields_set:
            _dict['grademethod'] = None

        # set to None if groupingid (nullable) is None
        # and model_fields_set contains the field
        if self.groupingid is None and "groupingid" in self.model_fields_set:
            _dict['groupingid'] = None

        # set to None if groupmode (nullable) is None
        # and model_fields_set contains the field
        if self.groupmode is None and "groupmode" in self.model_fields_set:
            _dict['groupmode'] = None

        # set to None if hasfeedback (nullable) is None
        # and model_fields_set contains the field
        if self.hasfeedback is None and "hasfeedback" in self.model_fields_set:
            _dict['hasfeedback'] = None

        # set to None if hasquestions (nullable) is None
        # and model_fields_set contains the field
        if self.hasquestions is None and "hasquestions" in self.model_fields_set:
            _dict['hasquestions'] = None

        # set to None if id (nullable) is None
        # and model_fields_set contains the field
        if self.id is None and "id" in self.model_fields_set:
            _dict['id'] = None

        # set to None if intro (nullable) is None
        # and model_fields_set contains the field
        if self.intro is None and "intro" in self.model_fields_set:
            _dict['intro'] = None

        # set to None if introformat (nullable) is None
        # and model_fields_set contains the field
        if self.introformat is None and "introformat" in self.model_fields_set:
            _dict['introformat'] = None

        # set to None if lang (nullable) is None
        # and model_fields_set contains the field
        if self.lang is None and "lang" in self.model_fields_set:
            _dict['lang'] = None

        # set to None if name (nullable) is None
        # and model_fields_set contains the field
        if self.name is None and "name" in self.model_fields_set:
            _dict['name'] = None

        # set to None if navmethod (nullable) is None
        # and model_fields_set contains the field
        if self.navmethod is None and "navmethod" in self.model_fields_set:
            _dict['navmethod'] = None

        # set to None if overduehandling (nullable) is None
        # and model_fields_set contains the field
        if self.overduehandling is None and "overduehandling" in self.model_fields_set:
            _dict['overduehandling'] = None

        # set to None if password (nullable) is None
        # and model_fields_set contains the field
        if self.password is None and "password" in self.model_fields_set:
            _dict['password'] = None

        # set to None if precreateattempts (nullable) is None
        # and model_fields_set contains the field
        if self.precreateattempts is None and "precreateattempts" in self.model_fields_set:
            _dict['precreateattempts'] = None

        # set to None if preferredbehaviour (nullable) is None
        # and model_fields_set contains the field
        if self.preferredbehaviour is None and "preferredbehaviour" in self.model_fields_set:
            _dict['preferredbehaviour'] = None

        # set to None if questiondecimalpoints (nullable) is None
        # and model_fields_set contains the field
        if self.questiondecimalpoints is None and "questiondecimalpoints" in self.model_fields_set:
            _dict['questiondecimalpoints'] = None

        # set to None if questionsperpage (nullable) is None
        # and model_fields_set contains the field
        if self.questionsperpage is None and "questionsperpage" in self.model_fields_set:
            _dict['questionsperpage'] = None

        # set to None if reviewattempt (nullable) is None
        # and model_fields_set contains the field
        if self.reviewattempt is None and "reviewattempt" in self.model_fields_set:
            _dict['reviewattempt'] = None

        # set to None if reviewcorrectness (nullable) is None
        # and model_fields_set contains the field
        if self.reviewcorrectness is None and "reviewcorrectness" in self.model_fields_set:
            _dict['reviewcorrectness'] = None

        # set to None if reviewgeneralfeedback (nullable) is None
        # and model_fields_set contains the field
        if self.reviewgeneralfeedback is None and "reviewgeneralfeedback" in self.model_fields_set:
            _dict['reviewgeneralfeedback'] = None

        # set to None if reviewmarks (nullable) is None
        # and model_fields_set contains the field
        if self.reviewmarks is None and "reviewmarks" in self.model_fields_set:
            _dict['reviewmarks'] = None

        # set to None if reviewmaxmarks (nullable) is None
        # and model_fields_set contains the field
        if self.reviewmaxmarks is None and "reviewmaxmarks" in self.model_fields_set:
            _dict['reviewmaxmarks'] = None

        # set to None if reviewoverallfeedback (nullable) is None
        # and model_fields_set contains the field
        if self.reviewoverallfeedback is None and "reviewoverallfeedback" in self.model_fields_set:
            _dict['reviewoverallfeedback'] = None

        # set to None if reviewrightanswer (nullable) is None
        # and model_fields_set contains the field
        if self.reviewrightanswer is None and "reviewrightanswer" in self.model_fields_set:
            _dict['reviewrightanswer'] = None

        # set to None if reviewspecificfeedback (nullable) is None
        # and model_fields_set contains the field
        if self.reviewspecificfeedback is None and "reviewspecificfeedback" in self.model_fields_set:
            _dict['reviewspecificfeedback'] = None

        # set to None if section (nullable) is None
        # and model_fields_set contains the field
        if self.section is None and "section" in self.model_fields_set:
            _dict['section'] = None

        # set to None if showblocks (nullable) is None
        # and model_fields_set contains the field
        if self.showblocks is None and "showblocks" in self.model_fields_set:
            _dict['showblocks'] = None

        # set to None if showuserpicture (nullable) is None
        # and model_fields_set contains the field
        if self.showuserpicture is None and "showuserpicture" in self.model_fields_set:
            _dict['showuserpicture'] = None

        # set to None if shuffleanswers (nullable) is None
        # and model_fields_set contains the field
        if self.shuffleanswers is None and "shuffleanswers" in self.model_fields_set:
            _dict['shuffleanswers'] = None

        # set to None if subnet (nullable) is None
        # and model_fields_set contains the field
        if self.subnet is None and "subnet" in self.model_fields_set:
            _dict['subnet'] = None

        # set to None if sumgrades (nullable) is None
        # and model_fields_set contains the field
        if self.sumgrades is None and "sumgrades" in self.model_fields_set:
            _dict['sumgrades'] = None

        # set to None if timeclose (nullable) is None
        # and model_fields_set contains the field
        if self.timeclose is None and "timeclose" in self.model_fields_set:
            _dict['timeclose'] = None

        # set to None if timecreated (nullable) is None
        # and model_fields_set contains the field
        if self.timecreated is None and "timecreated" in self.model_fields_set:
            _dict['timecreated'] = None

        # set to None if timelimit (nullable) is None
        # and model_fields_set contains the field
        if self.timelimit is None and "timelimit" in self.model_fields_set:
            _dict['timelimit'] = None

        # set to None if timemodified (nullable) is None
        # and model_fields_set contains the field
        if self.timemodified is None and "timemodified" in self.model_fields_set:
            _dict['timemodified'] = None

        # set to None if timeopen (nullable) is None
        # and model_fields_set contains the field
        if self.timeopen is None and "timeopen" in self.model_fields_set:
            _dict['timeopen'] = None

        # set to None if visible (nullable) is None
        # and model_fields_set contains the field
        if self.visible is None and "visible" in self.model_fields_set:
            _dict['visible'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ModQuizGetQuizzesByCoursesResponseQuizzesInner from a dict"""
        if obj is None:
            return None

        relaxed = settings.relaxe_all_models or "ModQuizGetQuizzesByCoursesResponseQuizzesInner" in settings.relaxed_models

        if not isinstance(obj, dict):
            return cls.model_construct(**obj) if relaxed else cls.model_validate(obj)

        data = {
            "allowofflineattempts": obj.get("allowofflineattempts"),
            "attemptonlast": obj.get("attemptonlast"),
            "attempts": obj.get("attempts"),
            "autosaveperiod": obj.get("autosaveperiod"),
            "browsersecurity": obj.get("browsersecurity"),
            "canredoquestions": obj.get("canredoquestions"),
            "completionattemptsexhausted": obj.get("completionattemptsexhausted"),
            "completionpass": obj.get("completionpass"),
            "course": obj.get("course"),
            "coursemodule": obj.get("coursemodule"),
            "decimalpoints": obj.get("decimalpoints"),
            "delay1": obj.get("delay1"),
            "delay2": obj.get("delay2"),
            "graceperiod": obj.get("graceperiod"),
            "grade": obj.get("grade"),
            "grademethod": obj.get("grademethod"),
            "groupingid": obj.get("groupingid"),
            "groupmode": obj.get("groupmode"),
            "hasfeedback": obj.get("hasfeedback"),
            "hasquestions": obj.get("hasquestions"),
            "id": obj.get("id"),
            "intro": obj.get("intro"),
            "introfiles": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["introfiles"]] if obj.get("introfiles") is not None else None,
            "introformat": obj.get("introformat"),
            "lang": obj.get("lang"),
            "name": obj.get("name"),
            "navmethod": obj.get("navmethod"),
            "overduehandling": obj.get("overduehandling"),
            "password": obj.get("password"),
            "precreateattempts": obj.get("precreateattempts"),
            "preferredbehaviour": obj.get("preferredbehaviour"),
            "questiondecimalpoints": obj.get("questiondecimalpoints"),
            "questionsperpage": obj.get("questionsperpage"),
            "reviewattempt": obj.get("reviewattempt"),
            "reviewcorrectness": obj.get("reviewcorrectness"),
            "reviewgeneralfeedback": obj.get("reviewgeneralfeedback"),
            "reviewmarks": obj.get("reviewmarks"),
            "reviewmaxmarks": obj.get("reviewmaxmarks"),
            "reviewoverallfeedback": obj.get("reviewoverallfeedback"),
            "reviewrightanswer": obj.get("reviewrightanswer"),
            "reviewspecificfeedback": obj.get("reviewspecificfeedback"),
            "section": obj.get("section"),
            "showblocks": obj.get("showblocks"),
            "showuserpicture": obj.get("showuserpicture"),
            "shuffleanswers": obj.get("shuffleanswers"),
            "subnet": obj.get("subnet"),
            "sumgrades": obj.get("sumgrades"),
            "timeclose": obj.get("timeclose"),
            "timecreated": obj.get("timecreated"),
            "timelimit": obj.get("timelimit"),
            "timemodified": obj.get("timemodified"),
            "timeopen": obj.get("timeopen"),
            "visible": obj.get("visible")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


