# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.mod_lesson_get_page_data_response_page import ModLessonGetPageDataResponsePage
from poodle_async_full.models.mod_lesson_get_user_attempt_response_answerpages_inner_answerdata import ModLessonGetUserAttemptResponseAnswerpagesInnerAnswerdata
from typing import Optional, Set
from typing_extensions import Self

class ModLessonGetUserAttemptResponseAnswerpagesInner(BaseModel):
    """
    ModLessonGetUserAttemptResponseAnswerpagesInner
    """ # noqa: E501
    answerdata: Optional[ModLessonGetUserAttemptResponseAnswerpagesInnerAnswerdata] = None
    contents: Optional[StrictStr] = Field(description="Page contents.")
    grayout: Optional[StrictInt] = Field(description="If is required to apply a grayout.")
    page: Optional[ModLessonGetPageDataResponsePage] = None
    qtype: Optional[StrictStr] = Field(description="Identifies the page type of this page.")
    title: Optional[StrictStr] = Field(description="Page title.")
    __properties: ClassVar[List[str]] = ["answerdata", "contents", "grayout", "page", "qtype", "title"]

    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 ModLessonGetUserAttemptResponseAnswerpagesInner 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 answerdata
        if self.answerdata:
            _dict['answerdata'] = self.answerdata.to_dict()
        # override the default output from pydantic by calling `to_dict()` of page
        if self.page:
            _dict['page'] = self.page.to_dict()
        # set to None if contents (nullable) is None
        # and model_fields_set contains the field
        if self.contents is None and "contents" in self.model_fields_set:
            _dict['contents'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "answerdata": ModLessonGetUserAttemptResponseAnswerpagesInnerAnswerdata.from_dict(obj["answerdata"]) if obj.get("answerdata") is not None else None,
            "contents": obj.get("contents"),
            "grayout": obj.get("grayout"),
            "page": ModLessonGetPageDataResponsePage.from_dict(obj["page"]) if obj.get("page") is not None else None,
            "qtype": obj.get("qtype"),
            "title": obj.get("title")
        })
        return _obj


