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

from poodle_async_full.configuration import settings

class GradereportUserGetGradeItemsResponseUsergradesInnerGradeitemsInner(BaseModel):
    """
    Grade items
    """ # noqa: E501
    averageformatted: Optional[StrictStr] = Field(default=None, description="Grade average")
    categoryid: Optional[StrictInt] = Field(description="Grade item category id")
    cmid: Optional[StrictInt] = Field(default=None, description="Course module id (if type mod)")
    feedback: Optional[StrictStr] = Field(default=None, description="Grade feedback")
    feedbackformat: Optional[StrictInt] = Field(default=None, description="feedback format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    gradedategraded: Optional[StrictInt] = Field(default=None, description="Grade graded date")
    gradedatesubmitted: Optional[StrictInt] = Field(default=None, description="Grade submit date")
    gradeformatted: Optional[StrictStr] = Field(default=None, description="The grade formatted")
    gradehiddenbydate: Optional[StrictBool] = Field(default=None, description="Grade hidden by date?")
    gradeishidden: Optional[StrictBool] = Field(default=None, description="Grade is hidden?")
    gradeislocked: Optional[StrictBool] = Field(default=None, description="Grade is locked?")
    gradeisoverridden: Optional[StrictBool] = Field(default=None, description="Grade overridden?")
    grademax: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Grade max")
    grademin: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Grade min")
    gradeneedsupdate: Optional[StrictBool] = Field(default=None, description="Grade needs update?")
    graderaw: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Grade raw")
    id: Optional[StrictInt] = Field(description="Grade item id")
    idnumber: Optional[StrictStr] = Field(description="Grade item idnumber")
    iteminstance: Optional[StrictInt] = Field(description="Grade item instance")
    itemmodule: Optional[StrictStr] = Field(description="Grade item module")
    itemname: Optional[StrictStr] = Field(description="Grade item name")
    itemnumber: Optional[StrictInt] = Field(description="Grade item item number")
    itemtype: Optional[StrictStr] = Field(description="Grade item type")
    lettergradeformatted: Optional[StrictStr] = Field(default=None, description="Letter grade")
    locked: Optional[StrictBool] = Field(default=None, description="Grade item for user locked?")
    numusers: Optional[StrictInt] = Field(default=None, description="Num users in course")
    outcomeid: Optional[StrictInt] = Field(description="Outcome id")
    percentageformatted: Optional[StrictStr] = Field(default=None, description="Percentage")
    rangeformatted: Optional[StrictStr] = Field(default=None, description="Range formatted")
    rank: Optional[StrictInt] = Field(default=None, description="Rank in the course")
    scaleid: Optional[StrictInt] = Field(description="Scale id")
    status: Optional[StrictStr] = Field(default=None, description="Status")
    weightformatted: Optional[StrictStr] = Field(default=None, description="Weight")
    weightraw: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Weight raw")
    __properties: ClassVar[List[str]] = ["averageformatted", "categoryid", "cmid", "feedback", "feedbackformat", "gradedategraded", "gradedatesubmitted", "gradeformatted", "gradehiddenbydate", "gradeishidden", "gradeislocked", "gradeisoverridden", "grademax", "grademin", "gradeneedsupdate", "graderaw", "id", "idnumber", "iteminstance", "itemmodule", "itemname", "itemnumber", "itemtype", "lettergradeformatted", "locked", "numusers", "outcomeid", "percentageformatted", "rangeformatted", "rank", "scaleid", "status", "weightformatted", "weightraw"]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "averageformatted": obj.get("averageformatted"),
            "categoryid": obj.get("categoryid"),
            "cmid": obj.get("cmid"),
            "feedback": obj.get("feedback"),
            "feedbackformat": obj.get("feedbackformat"),
            "gradedategraded": obj.get("gradedategraded"),
            "gradedatesubmitted": obj.get("gradedatesubmitted"),
            "gradeformatted": obj.get("gradeformatted"),
            "gradehiddenbydate": obj.get("gradehiddenbydate"),
            "gradeishidden": obj.get("gradeishidden"),
            "gradeislocked": obj.get("gradeislocked"),
            "gradeisoverridden": obj.get("gradeisoverridden"),
            "grademax": obj.get("grademax"),
            "grademin": obj.get("grademin"),
            "gradeneedsupdate": obj.get("gradeneedsupdate"),
            "graderaw": obj.get("graderaw"),
            "id": obj.get("id"),
            "idnumber": obj.get("idnumber"),
            "iteminstance": obj.get("iteminstance"),
            "itemmodule": obj.get("itemmodule"),
            "itemname": obj.get("itemname"),
            "itemnumber": obj.get("itemnumber"),
            "itemtype": obj.get("itemtype"),
            "lettergradeformatted": obj.get("lettergradeformatted"),
            "locked": obj.get("locked"),
            "numusers": obj.get("numusers"),
            "outcomeid": obj.get("outcomeid"),
            "percentageformatted": obj.get("percentageformatted"),
            "rangeformatted": obj.get("rangeformatted"),
            "rank": obj.get("rank"),
            "scaleid": obj.get("scaleid"),
            "status": obj.get("status"),
            "weightformatted": obj.get("weightformatted"),
            "weightraw": obj.get("weightraw")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


