# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModLessonGetPageDataResponsePage(BaseModel):
    """
    Page fields
    """ # noqa: E501
    contents: Optional[StrictStr] = Field(default=None, description="The contents of this page")
    contentsformat: Optional[StrictInt] = Field(default=None, description="contents format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    display: Optional[StrictInt] = Field(description="Used to record page specific display selections")
    displayinmenublock: Optional[StrictBool] = Field(description="Toggles display in the left menu block")
    id: Optional[StrictInt] = Field(description="The id of this lesson page")
    layout: Optional[StrictInt] = Field(description="Used to record page specific layout selections")
    lessonid: Optional[StrictInt] = Field(description="The id of the lesson this page belongs to")
    nextpageid: Optional[StrictInt] = Field(description="The id of the next page in the page sequence")
    prevpageid: Optional[StrictInt] = Field(description="The id of the page before this one")
    qoption: Optional[StrictInt] = Field(description="Used to record page type specific options")
    qtype: Optional[StrictInt] = Field(description="Identifies the page type of this page")
    timecreated: Optional[StrictInt] = Field(description="Timestamp for when the page was created")
    timemodified: Optional[StrictInt] = Field(description="Timestamp for when the page was last modified")
    title: Optional[StrictStr] = Field(default=None, description="The title of this page")
    type: Optional[StrictInt] = Field(description="The type of the page [question | structure]")
    typeid: Optional[StrictInt] = Field(description="The unique identifier for the page type")
    typestring: Optional[StrictStr] = Field(description="The string that describes this page type")
    __properties: ClassVar[List[str]] = ["contents", "contentsformat", "display", "displayinmenublock", "id", "layout", "lessonid", "nextpageid", "prevpageid", "qoption", "qtype", "timecreated", "timemodified", "title", "type", "typeid", "typestring"]

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

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

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

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

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

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

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

        # 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

        # 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

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

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

        return _dict

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

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

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

        data = {
            "contents": obj.get("contents"),
            "contentsformat": obj.get("contentsformat"),
            "display": obj.get("display"),
            "displayinmenublock": obj.get("displayinmenublock"),
            "id": obj.get("id"),
            "layout": obj.get("layout"),
            "lessonid": obj.get("lessonid"),
            "nextpageid": obj.get("nextpageid"),
            "prevpageid": obj.get("prevpageid"),
            "qoption": obj.get("qoption"),
            "qtype": obj.get("qtype"),
            "timecreated": obj.get("timecreated"),
            "timemodified": obj.get("timemodified"),
            "title": obj.get("title"),
            "type": obj.get("type"),
            "typeid": obj.get("typeid"),
            "typestring": obj.get("typestring")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


