# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
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 ModLessonGetPageDataResponseAnswersInner(BaseModel):
    """
    The page answers
    """ # noqa: E501
    answer: Optional[StrictStr] = Field(default=None, description="Possible answer text")
    answerfiles: List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner] = Field(description="List of files.")
    answerformat: Optional[StrictInt] = Field(default=None, description="answer format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    flags: Optional[StrictInt] = Field(default=None, description="Used to store options for the answer")
    grade: Optional[StrictInt] = Field(default=None, description="The grade this answer is worth")
    id: Optional[StrictInt] = Field(description="The ID of this answer in the database")
    jumpto: Optional[StrictInt] = Field(default=None, description="Identifies where the user goes upon completing a page with this answer")
    response: Optional[StrictStr] = Field(default=None, description="Response text for the answer")
    responsefiles: List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner] = Field(description="List of files.")
    responseformat: Optional[StrictInt] = Field(default=None, description="response format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    score: Optional[StrictInt] = Field(default=None, description="The score this answer will give")
    timecreated: Optional[StrictInt] = Field(default=None, description="A timestamp of when the answer was created")
    timemodified: Optional[StrictInt] = Field(default=None, description="A timestamp of when the answer was modified")
    __properties: ClassVar[List[str]] = ["answer", "answerfiles", "answerformat", "flags", "grade", "id", "jumpto", "response", "responsefiles", "responseformat", "score", "timecreated", "timemodified"]

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

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

        # set to None if flags (nullable) is None
        # and model_fields_set contains the field
        if self.flags is None and "flags" in self.model_fields_set:
            _dict['flags'] = 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 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 jumpto (nullable) is None
        # and model_fields_set contains the field
        if self.jumpto is None and "jumpto" in self.model_fields_set:
            _dict['jumpto'] = 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 responseformat (nullable) is None
        # and model_fields_set contains the field
        if self.responseformat is None and "responseformat" in self.model_fields_set:
            _dict['responseformat'] = None

        # set to None if score (nullable) is None
        # and model_fields_set contains the field
        if self.score is None and "score" in self.model_fields_set:
            _dict['score'] = 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 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

        return _dict

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

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

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

        data = {
            "answer": obj.get("answer"),
            "answerfiles": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["answerfiles"]] if obj.get("answerfiles") is not None else None,
            "answerformat": obj.get("answerformat"),
            "flags": obj.get("flags"),
            "grade": obj.get("grade"),
            "id": obj.get("id"),
            "jumpto": obj.get("jumpto"),
            "response": obj.get("response"),
            "responsefiles": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["responsefiles"]] if obj.get("responsefiles") is not None else None,
            "responseformat": obj.get("responseformat"),
            "score": obj.get("score"),
            "timecreated": obj.get("timecreated"),
            "timemodified": obj.get("timemodified")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


