# 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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_mini.models.gradereport_user_get_grade_items_response_usergrades_inner_gradeitems_inner import GradereportUserGetGradeItemsResponseUsergradesInnerGradeitemsInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_mini.configuration import settings

class GradereportUserGetGradeItemsResponseUsergradesInner(BaseModel):
    """
    GradereportUserGetGradeItemsResponseUsergradesInner
    """ # noqa: E501
    courseid: Optional[StrictInt] = Field(description="course id")
    courseidnumber: Optional[StrictStr] = Field(description="course idnumber")
    gradeitems: List[GradereportUserGetGradeItemsResponseUsergradesInnerGradeitemsInner]
    maxdepth: Optional[StrictInt] = Field(description="table max depth (needed for printing it)")
    userfullname: Optional[StrictStr] = Field(description="user fullname")
    userid: Optional[StrictInt] = Field(description="user id")
    useridnumber: Optional[StrictStr] = Field(description="user idnumber")
    __properties: ClassVar[List[str]] = ["courseid", "courseidnumber", "gradeitems", "maxdepth", "userfullname", "userid", "useridnumber"]

    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 GradereportUserGetGradeItemsResponseUsergradesInner 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 gradeitems (list)
        _items = []
        if self.gradeitems:
            for _item_gradeitems in self.gradeitems:
                if _item_gradeitems:
                    _items.append(_item_gradeitems.to_dict())
            _dict['gradeitems'] = _items
        # set to None if courseid (nullable) is None
        # and model_fields_set contains the field
        if self.courseid is None and "courseid" in self.model_fields_set:
            _dict['courseid'] = None

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

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

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

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

        return _dict

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

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

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

        data = {
            "courseid": obj.get("courseid"),
            "courseidnumber": obj.get("courseidnumber"),
            "gradeitems": [GradereportUserGetGradeItemsResponseUsergradesInnerGradeitemsInner.from_dict(_item) for _item in obj["gradeitems"]] if obj.get("gradeitems") is not None else None,
            "maxdepth": obj.get("maxdepth"),
            "userfullname": obj.get("userfullname"),
            "userid": obj.get("userid"),
            "useridnumber": obj.get("useridnumber")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


