# 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.mod_quiz_get_attempt_data_response_questions_inner_responsefileareas_inner import ModQuizGetAttemptDataResponseQuestionsInnerResponsefileareasInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModQuizGetAttemptDataResponseQuestionsInner(BaseModel):
    """
    The question data. Some fields may not be returned depending on the quiz display settings.
    """ # noqa: E501
    blockedbyprevious: Optional[StrictBool] = Field(default=None, description="whether the question is blocked by the previous question")
    flagged: Optional[StrictBool] = Field(description="whether the question is flagged or not")
    hasautosavedstep: Optional[StrictBool] = Field(default=None, description="whether this question attempt has autosaved data")
    html: Optional[StrictStr] = Field(description="the question rendered")
    lastactiontime: Optional[StrictInt] = Field(default=None, description="the timestamp of the most recent step in this question attempt")
    mark: Optional[StrictStr] = Field(default=None, description="the mark awarded.                     It will be returned only if the user is allowed to see it.")
    maxmark: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="the maximum mark possible for this question attempt.                     It will be returned only if the user is allowed to see it.")
    number: Optional[StrictInt] = Field(default=None, description="DO NOT USE. Use questionnumber. Only retained for backwards compatibility.")
    page: Optional[StrictInt] = Field(description="page of the quiz this question appears on")
    questionnumber: Optional[StrictStr] = Field(description="The question number to display for this question, e.g. \"7\", \"i\" or \"Custom-B)\".")
    responsefileareas: Optional[List[ModQuizGetAttemptDataResponseQuestionsInnerResponsefileareasInner]] = Field(default=None, description="Response file areas including files")
    sequencecheck: Optional[StrictInt] = Field(default=None, description="the number of real steps in this attempt")
    settings: Optional[StrictStr] = Field(default=None, description="Question settings (JSON encoded).")
    slot: Optional[StrictInt] = Field(description="slot number")
    state: Optional[StrictStr] = Field(default=None, description="the state where the question is in terms of correctness.                     It will not be returned if the user cannot see it due to the quiz display correctness settings.")
    stateclass: Optional[StrictStr] = Field(default=None, description="A machine-readable class name for the state that this question attempt is in, as returned by question_usage_by_activity::get_question_state_class().                     Always returned.")
    status: Optional[StrictStr] = Field(default=None, description="Human readable state of the question.")
    type: Optional[StrictStr] = Field(description="question type, i.e: multichoice")
    __properties: ClassVar[List[str]] = ["blockedbyprevious", "flagged", "hasautosavedstep", "html", "lastactiontime", "mark", "maxmark", "number", "page", "questionnumber", "responsefileareas", "sequencecheck", "settings", "slot", "state", "stateclass", "status", "type"]

    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 ModQuizGetAttemptDataResponseQuestionsInner 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 responsefileareas (list)
        _items = []
        if self.responsefileareas:
            for _item_responsefileareas in self.responsefileareas:
                if _item_responsefileareas:
                    _items.append(_item_responsefileareas.to_dict())
            _dict['responsefileareas'] = _items
        # set to None if blockedbyprevious (nullable) is None
        # and model_fields_set contains the field
        if self.blockedbyprevious is None and "blockedbyprevious" in self.model_fields_set:
            _dict['blockedbyprevious'] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "blockedbyprevious": obj.get("blockedbyprevious"),
            "flagged": obj.get("flagged"),
            "hasautosavedstep": obj.get("hasautosavedstep"),
            "html": obj.get("html"),
            "lastactiontime": obj.get("lastactiontime"),
            "mark": obj.get("mark"),
            "maxmark": obj.get("maxmark"),
            "number": obj.get("number"),
            "page": obj.get("page"),
            "questionnumber": obj.get("questionnumber"),
            "responsefileareas": [ModQuizGetAttemptDataResponseQuestionsInnerResponsefileareasInner.from_dict(_item) for _item in obj["responsefileareas"]] if obj.get("responsefileareas") is not None else None,
            "sequencecheck": obj.get("sequencecheck"),
            "settings": obj.get("settings"),
            "slot": obj.get("slot"),
            "state": obj.get("state"),
            "stateclass": obj.get("stateclass"),
            "status": obj.get("status"),
            "type": obj.get("type")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


