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

class ModLessonGetUserAttemptGradeResponseGrade(BaseModel):
    """
    Attempt grade
    """ # noqa: E501
    attempts: Optional[StrictInt] = Field(description="Number of question attempts")
    earned: Optional[Union[StrictFloat, StrictInt]] = Field(description="Points earned by student")
    grade: Optional[Union[StrictFloat, StrictInt]] = Field(description="Calculated percentage grade")
    manualpoints: Optional[Union[StrictFloat, StrictInt]] = Field(description="Point value for manually graded questions")
    nmanual: Optional[StrictInt] = Field(description="Number of manually graded questions")
    nquestions: Optional[StrictInt] = Field(description="Number of questions answered")
    total: Optional[Union[StrictFloat, StrictInt]] = Field(description="Max points possible")
    __properties: ClassVar[List[str]] = ["attempts", "earned", "grade", "manualpoints", "nmanual", "nquestions", "total"]

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "attempts": obj.get("attempts"),
            "earned": obj.get("earned"),
            "grade": obj.get("grade"),
            "manualpoints": obj.get("manualpoints"),
            "nmanual": obj.get("nmanual"),
            "nquestions": obj.get("nquestions"),
            "total": obj.get("total")
        })
        return _obj


