# 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 CoreGradesUpdateGradesParametersItemdetails(BaseModel):
    """
    Any grade item settings to alter
    """ # noqa: E501
    deleted: Optional[StrictBool] = Field(default=None, description="True if the grade item should be deleted")
    grademax: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Maximum grade allowed")
    grademin: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Minimum grade allowed")
    gradetype: Optional[StrictInt] = Field(default=None, description="The type of grade (0 = none, 1 = value, 2 = scale, 3 = text)")
    hidden: Optional[StrictBool] = Field(default=None, description="True if the grade item is hidden")
    idnumber: Optional[StrictInt] = Field(default=None, description="Arbitrary ID provided by the module responsible for the grade item")
    itemname: Optional[StrictStr] = Field(default=None, description="The grade item name")
    multfactor: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Multiply all grades by this number")
    plusfactor: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Add this to all grades")
    scaleid: Optional[StrictInt] = Field(default=None, description="The ID of the custom scale being is used")
    __properties: ClassVar[List[str]] = ["deleted", "grademax", "grademin", "gradetype", "hidden", "idnumber", "itemname", "multfactor", "plusfactor", "scaleid"]

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

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

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

        return _dict

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

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

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

        data = {
            "deleted": obj.get("deleted"),
            "grademax": obj.get("grademax"),
            "grademin": obj.get("grademin"),
            "gradetype": obj.get("gradetype"),
            "hidden": obj.get("hidden"),
            "idnumber": obj.get("idnumber"),
            "itemname": obj.get("itemname"),
            "multfactor": obj.get("multfactor"),
            "plusfactor": obj.get("plusfactor"),
            "scaleid": obj.get("scaleid")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


