# 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 poodle_async_full.models.gradingform_guide_grader_gradingpanel_fetch_response_grade_comments_inner import GradingformGuideGraderGradingpanelFetchResponseGradeCommentsInner
from poodle_async_full.models.gradingform_guide_grader_gradingpanel_fetch_response_grade_criterion_inner import GradingformGuideGraderGradingpanelFetchResponseGradeCriterionInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class GradingformGuideGraderGradingpanelFetchResponseGrade(BaseModel):
    """
    GradingformGuideGraderGradingpanelFetchResponseGrade
    """ # noqa: E501
    comments: List[GradingformGuideGraderGradingpanelFetchResponseGradeCommentsInner] = Field(description="Frequently used comments")
    criterion: List[GradingformGuideGraderGradingpanelFetchResponseGradeCriterionInner] = Field(description="The criterion by which this item will be graded")
    gradedby: Optional[StrictStr] = Field(description="The assumed grader of this grading instance")
    hascomments: Optional[StrictBool] = Field(description="Whether there are any frequently-used comments")
    instanceid: Optional[StrictInt] = Field(description="The id of the current grading instance")
    maxgrade: Optional[StrictStr] = Field(description="Max possible grade")
    timecreated: Optional[StrictInt] = Field(description="The time that the grade was created")
    timemodified: Optional[StrictInt] = Field(description="The time that the grade was last updated")
    usergrade: Optional[StrictStr] = Field(description="Current user grade")
    __properties: ClassVar[List[str]] = ["comments", "criterion", "gradedby", "hascomments", "instanceid", "maxgrade", "timecreated", "timemodified", "usergrade"]

    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 GradingformGuideGraderGradingpanelFetchResponseGrade 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 comments (list)
        _items = []
        if self.comments:
            for _item_comments in self.comments:
                if _item_comments:
                    _items.append(_item_comments.to_dict())
            _dict['comments'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in criterion (list)
        _items = []
        if self.criterion:
            for _item_criterion in self.criterion:
                if _item_criterion:
                    _items.append(_item_criterion.to_dict())
            _dict['criterion'] = _items
        # set to None if gradedby (nullable) is None
        # and model_fields_set contains the field
        if self.gradedby is None and "gradedby" in self.model_fields_set:
            _dict['gradedby'] = None

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

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

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

        return _dict

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

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

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

        data = {
            "comments": [GradingformGuideGraderGradingpanelFetchResponseGradeCommentsInner.from_dict(_item) for _item in obj["comments"]] if obj.get("comments") is not None else None,
            "criterion": [GradingformGuideGraderGradingpanelFetchResponseGradeCriterionInner.from_dict(_item) for _item in obj["criterion"]] if obj.get("criterion") is not None else None,
            "gradedby": obj.get("gradedby"),
            "hascomments": obj.get("hascomments"),
            "instanceid": obj.get("instanceid"),
            "maxgrade": obj.get("maxgrade"),
            "timecreated": obj.get("timecreated"),
            "timemodified": obj.get("timemodified"),
            "usergrade": obj.get("usergrade")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


