# 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 typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreGradesCreateGradecategoriesParametersCategoriesInnerOptions(BaseModel):
    """
    optional category data
    """ # noqa: E501
    aggregateonlygraded: Optional[StrictBool] = Field(default=None, description="exclude empty grades")
    aggregateoutcomes: Optional[StrictBool] = Field(default=None, description="aggregate outcomes")
    aggregation: Optional[StrictInt] = Field(default=None, description="aggregation method")
    aggregationcoef2: Optional[StrictStr] = Field(default=None, description="weight coefficient")
    decimals: Optional[StrictInt] = Field(default=None, description="the decimal count")
    display: Optional[StrictInt] = Field(default=None, description="the display type")
    droplow: Optional[StrictInt] = Field(default=None, description="drop low grades")
    grademax: Optional[StrictInt] = Field(default=None, description="the grade max")
    grademin: Optional[StrictInt] = Field(default=None, description="the grade min")
    gradepass: Optional[StrictInt] = Field(default=None, description="the grade to pass")
    gradetype: Optional[StrictInt] = Field(default=None, description="the grade type")
    hiddenuntil: Optional[StrictInt] = Field(default=None, description="grades hidden until")
    idnumber: Optional[StrictStr] = Field(default=None, description="the category idnumber")
    iteminfo: Optional[StrictStr] = Field(default=None, description="the category iteminfo")
    itemname: Optional[StrictStr] = Field(default=None, description="the category total name")
    locktime: Optional[StrictInt] = Field(default=None, description="lock grades after")
    parentcategoryid: Optional[StrictInt] = Field(default=None, description="The parent category id")
    parentcategoryidnumber: Optional[StrictStr] = Field(default=None, description="the parent category idnumber")
    weightoverride: Optional[StrictBool] = Field(default=None, description="weight adjusted")
    __properties: ClassVar[List[str]] = ["aggregateonlygraded", "aggregateoutcomes", "aggregation", "aggregationcoef2", "decimals", "display", "droplow", "grademax", "grademin", "gradepass", "gradetype", "hiddenuntil", "idnumber", "iteminfo", "itemname", "locktime", "parentcategoryid", "parentcategoryidnumber", "weightoverride"]

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "aggregateonlygraded": obj.get("aggregateonlygraded"),
            "aggregateoutcomes": obj.get("aggregateoutcomes"),
            "aggregation": obj.get("aggregation"),
            "aggregationcoef2": obj.get("aggregationcoef2"),
            "decimals": obj.get("decimals"),
            "display": obj.get("display"),
            "droplow": obj.get("droplow"),
            "grademax": obj.get("grademax"),
            "grademin": obj.get("grademin"),
            "gradepass": obj.get("gradepass"),
            "gradetype": obj.get("gradetype"),
            "hiddenuntil": obj.get("hiddenuntil"),
            "idnumber": obj.get("idnumber"),
            "iteminfo": obj.get("iteminfo"),
            "itemname": obj.get("itemname"),
            "locktime": obj.get("locktime"),
            "parentcategoryid": obj.get("parentcategoryid"),
            "parentcategoryidnumber": obj.get("parentcategoryidnumber"),
            "weightoverride": obj.get("weightoverride")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


