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

from poodle_async_full.configuration import settings

class ModWorkshopGetGradesReportResponseReportGradesInner(BaseModel):
    """
    ModWorkshopGetGradesReportResponseReportGradesInner
    """ # noqa: E501
    gradinggrade: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Computed grade for the assessment.")
    reviewedby: Optional[List[ModWorkshopGetGradesReportResponseReportGradesInnerReviewedbyInner]] = Field(default=None, description="The users who reviewed the                                         user submission.")
    reviewerof: Optional[List[ModWorkshopGetGradesReportResponseReportGradesInnerReviewedbyInner]] = Field(default=None, description="The assessments the user                                         reviewed.")
    submissiongrade: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Aggregated grade for the submission.")
    submissiongradeover: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Grade for the assessment overrided                                         by the teacher.")
    submissiongradeoverby: Optional[StrictInt] = Field(default=None, description="The id of the user who overrided                                         the grade.")
    submissionid: Optional[StrictInt] = Field(description="Submission id.")
    submissionmodified: Optional[StrictInt] = Field(description="Timestamp submission was updated.")
    submissionpublished: Optional[StrictInt] = Field(default=None, description="Whether is a submission published.")
    submissiontitle: Optional[StrictStr] = Field(description="Submission title.")
    userid: Optional[StrictInt] = Field(description="The id of the user being displayed in the report.")
    __properties: ClassVar[List[str]] = ["gradinggrade", "reviewedby", "reviewerof", "submissiongrade", "submissiongradeover", "submissiongradeoverby", "submissionid", "submissionmodified", "submissionpublished", "submissiontitle", "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 ModWorkshopGetGradesReportResponseReportGradesInner 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 reviewedby (list)
        _items = []
        if self.reviewedby:
            for _item_reviewedby in self.reviewedby:
                if _item_reviewedby:
                    _items.append(_item_reviewedby.to_dict())
            _dict['reviewedby'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in reviewerof (list)
        _items = []
        if self.reviewerof:
            for _item_reviewerof in self.reviewerof:
                if _item_reviewerof:
                    _items.append(_item_reviewerof.to_dict())
            _dict['reviewerof'] = _items
        # set to None if gradinggrade (nullable) is None
        # and model_fields_set contains the field
        if self.gradinggrade is None and "gradinggrade" in self.model_fields_set:
            _dict['gradinggrade'] = None

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

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

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

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

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

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

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

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

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

        data = {
            "gradinggrade": obj.get("gradinggrade"),
            "reviewedby": [ModWorkshopGetGradesReportResponseReportGradesInnerReviewedbyInner.from_dict(_item) for _item in obj["reviewedby"]] if obj.get("reviewedby") is not None else None,
            "reviewerof": [ModWorkshopGetGradesReportResponseReportGradesInnerReviewedbyInner.from_dict(_item) for _item in obj["reviewerof"]] if obj.get("reviewerof") is not None else None,
            "submissiongrade": obj.get("submissiongrade"),
            "submissiongradeover": obj.get("submissiongradeover"),
            "submissiongradeoverby": obj.get("submissiongradeoverby"),
            "submissionid": obj.get("submissionid"),
            "submissionmodified": obj.get("submissionmodified"),
            "submissionpublished": obj.get("submissionpublished"),
            "submissiontitle": obj.get("submissiontitle"),
            "userid": obj.get("userid")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


