# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.core_grading_get_definitions_response_areas_inner_definitions_inner_guide import CoreGradingGetDefinitionsResponseAreasInnerDefinitionsInnerGuide
from poodle_async_full.models.core_grading_get_definitions_response_areas_inner_definitions_inner_rubric import CoreGradingGetDefinitionsResponseAreasInnerDefinitionsInnerRubric
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreGradingGetDefinitionsResponseAreasInnerDefinitionsInner(BaseModel):
    """
    CoreGradingGetDefinitionsResponseAreasInnerDefinitionsInner
    """ # noqa: E501
    copiedfromid: Optional[StrictInt] = Field(default=None, description="copied from id")
    description: Optional[StrictStr] = Field(default=None, description="description")
    descriptionformat: Optional[StrictInt] = Field(default=None, description="description format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    guide: Optional[CoreGradingGetDefinitionsResponseAreasInnerDefinitionsInnerGuide] = None
    id: Optional[StrictInt] = Field(default=None, description="definition id")
    method: Optional[StrictStr] = Field(description="method")
    name: Optional[StrictStr] = Field(description="name")
    rubric: Optional[CoreGradingGetDefinitionsResponseAreasInnerDefinitionsInnerRubric] = None
    status: Optional[StrictInt] = Field(description="status")
    timecopied: Optional[StrictInt] = Field(default=None, description="time copied")
    timecreated: Optional[StrictInt] = Field(description="creation time")
    timemodified: Optional[StrictInt] = Field(description="last modified time")
    usercreated: Optional[StrictInt] = Field(description="user who created definition")
    usermodified: Optional[StrictInt] = Field(description="user who modified definition")
    __properties: ClassVar[List[str]] = ["copiedfromid", "description", "descriptionformat", "guide", "id", "method", "name", "rubric", "status", "timecopied", "timecreated", "timemodified", "usercreated", "usermodified"]

    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 CoreGradingGetDefinitionsResponseAreasInnerDefinitionsInner 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 guide
        if self.guide:
            _dict['guide'] = self.guide.to_dict()
        # override the default output from pydantic by calling `to_dict()` of rubric
        if self.rubric:
            _dict['rubric'] = self.rubric.to_dict()
        # set to None if copiedfromid (nullable) is None
        # and model_fields_set contains the field
        if self.copiedfromid is None and "copiedfromid" in self.model_fields_set:
            _dict['copiedfromid'] = None

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "copiedfromid": obj.get("copiedfromid"),
            "description": obj.get("description"),
            "descriptionformat": obj.get("descriptionformat"),
            "guide": CoreGradingGetDefinitionsResponseAreasInnerDefinitionsInnerGuide.from_dict(obj["guide"]) if obj.get("guide") is not None else None,
            "id": obj.get("id"),
            "method": obj.get("method"),
            "name": obj.get("name"),
            "rubric": CoreGradingGetDefinitionsResponseAreasInnerDefinitionsInnerRubric.from_dict(obj["rubric"]) if obj.get("rubric") is not None else None,
            "status": obj.get("status"),
            "timecopied": obj.get("timecopied"),
            "timecreated": obj.get("timecreated"),
            "timemodified": obj.get("timemodified"),
            "usercreated": obj.get("usercreated"),
            "usermodified": obj.get("usermodified")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


