# coding: utf-8

"""
    Moodle Webservice API

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

    The version of the OpenAPI document: 4.5 (Build: 20241007)
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.auth_email_get_signup_settings_response_warnings_inner import AuthEmailGetSignupSettingsResponseWarningsInner
from poodle_async_full.models.mod_lesson_finish_attempt_response_messages_inner import ModLessonFinishAttemptResponseMessagesInner
from typing import Optional, Set
from typing_extensions import Self

class ModLessonProcessPageResponse(BaseModel):
    """
    ModLessonProcessPageResponse
    """ # noqa: E501
    attemptsremaining: Optional[StrictInt] = Field(description="Number of attempts remaining.")
    correctanswer: Optional[StrictBool] = Field(description="Whether the answer is correct.")
    displaymenu: Optional[StrictBool] = Field(description="Whether we should display the menu or not in this page.")
    feedback: Optional[StrictStr] = Field(description="The response feedback.")
    inmediatejump: Optional[StrictBool] = Field(description="Whether the page processing redirect directly to anoter page.")
    isessayquestion: Optional[StrictBool] = Field(description="Whether is a essay question.")
    maxattemptsreached: Optional[StrictBool] = Field(description="Whether we reachered the max number of attempts.")
    messages: List[ModLessonFinishAttemptResponseMessagesInner]
    newpageid: Optional[StrictInt] = Field(description="New page id (if a jump was made).")
    noanswer: Optional[StrictBool] = Field(description="Whether there aren't answers.")
    nodefaultresponse: Optional[StrictBool] = Field(description="Whether there is not a default response.")
    ongoingscore: Optional[StrictStr] = Field(description="The ongoing message.")
    progress: Optional[StrictInt] = Field(description="Progress percentage in the lesson.")
    response: Optional[StrictStr] = Field(description="The response.")
    reviewmode: Optional[StrictBool] = Field(description="Whether the user is reviewing.")
    studentanswer: Optional[StrictStr] = Field(description="The student answer.")
    userresponse: Optional[StrictStr] = Field(description="The user response.")
    warnings: Optional[List[AuthEmailGetSignupSettingsResponseWarningsInner]] = Field(default=None, description="list of warnings")
    __properties: ClassVar[List[str]] = ["attemptsremaining", "correctanswer", "displaymenu", "feedback", "inmediatejump", "isessayquestion", "maxattemptsreached", "messages", "newpageid", "noanswer", "nodefaultresponse", "ongoingscore", "progress", "response", "reviewmode", "studentanswer", "userresponse", "warnings"]

    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 ModLessonProcessPageResponse 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 messages (list)
        _items = []
        if self.messages:
            for _item_messages in self.messages:
                if _item_messages:
                    _items.append(_item_messages.to_dict())
            _dict['messages'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in warnings (list)
        _items = []
        if self.warnings:
            for _item_warnings in self.warnings:
                if _item_warnings:
                    _items.append(_item_warnings.to_dict())
            _dict['warnings'] = _items
        # set to None if attemptsremaining (nullable) is None
        # and model_fields_set contains the field
        if self.attemptsremaining is None and "attemptsremaining" in self.model_fields_set:
            _dict['attemptsremaining'] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "attemptsremaining": obj.get("attemptsremaining"),
            "correctanswer": obj.get("correctanswer"),
            "displaymenu": obj.get("displaymenu"),
            "feedback": obj.get("feedback"),
            "inmediatejump": obj.get("inmediatejump"),
            "isessayquestion": obj.get("isessayquestion"),
            "maxattemptsreached": obj.get("maxattemptsreached"),
            "messages": [ModLessonFinishAttemptResponseMessagesInner.from_dict(_item) for _item in obj["messages"]] if obj.get("messages") is not None else None,
            "newpageid": obj.get("newpageid"),
            "noanswer": obj.get("noanswer"),
            "nodefaultresponse": obj.get("nodefaultresponse"),
            "ongoingscore": obj.get("ongoingscore"),
            "progress": obj.get("progress"),
            "response": obj.get("response"),
            "reviewmode": obj.get("reviewmode"),
            "studentanswer": obj.get("studentanswer"),
            "userresponse": obj.get("userresponse"),
            "warnings": [AuthEmailGetSignupSettingsResponseWarningsInner.from_dict(_item) for _item in obj["warnings"]] if obj.get("warnings") is not None else None
        })
        return _obj


