# coding: utf-8

"""
    Moodle Webservice API

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

    The version of the OpenAPI document: 5.0.2 (Build: 20250811)
    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
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class ModLessonGetContentPagesViewedResponsePagesInner(BaseModel):
    """
    The content pages viewed.
    """ # noqa: E501
    flag: Optional[StrictInt] = Field(description="1 if the next page was calculated randomly.")
    id: Optional[StrictInt] = Field(description="The attempt id.")
    lessonid: Optional[StrictInt] = Field(description="The lesson id.")
    nextpageid: Optional[StrictInt] = Field(description="The next page chosen id.")
    pageid: Optional[StrictInt] = Field(description="The page id.")
    retry: Optional[StrictInt] = Field(description="The lesson attempt number.")
    timeseen: Optional[StrictInt] = Field(description="The time the page was seen.")
    userid: Optional[StrictInt] = Field(description="The user who viewed the page.")
    __properties: ClassVar[List[str]] = ["flag", "id", "lessonid", "nextpageid", "pageid", "retry", "timeseen", "userid"]

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "flag": obj.get("flag"),
            "id": obj.get("id"),
            "lessonid": obj.get("lessonid"),
            "nextpageid": obj.get("nextpageid"),
            "pageid": obj.get("pageid"),
            "retry": obj.get("retry"),
            "timeseen": obj.get("timeseen"),
            "userid": obj.get("userid")
        })
        return _obj


