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

from poodle_async_full.configuration import settings

class ToolLpDataForUserCompetencySummaryInCourseResponseUsercompetencysummaryEvidenceInner(BaseModel):
    """
    ToolLpDataForUserCompetencySummaryInCourseResponseUsercompetencysummaryEvidenceInner
    """ # noqa: E501
    action: StrictInt = Field(description="action")
    actionuser: Optional[CoreCompetencyCreatePlanResponseReviewer] = None
    actionuserid: Optional[StrictInt] = Field(description="actionuserid")
    candelete: StrictBool = Field(description="candelete")
    contextid: StrictInt = Field(description="contextid")
    desca: Optional[StrictStr] = Field(description="desca")
    desccomponent: StrictStr = Field(description="desccomponent")
    descidentifier: StrictStr = Field(description="descidentifier")
    description: StrictStr = Field(description="description")
    grade: Optional[StrictInt] = Field(description="grade")
    gradename: StrictStr = Field(description="gradename")
    id: StrictInt = Field(description="id")
    note: Optional[StrictStr] = Field(description="note")
    timecreated: StrictInt = Field(description="timecreated")
    timemodified: StrictInt = Field(description="timemodified")
    url: Optional[StrictStr] = Field(description="url")
    usercompetencyid: StrictInt = Field(description="usercompetencyid")
    userdate: StrictStr = Field(description="userdate")
    usermodified: StrictInt = Field(description="usermodified")
    __properties: ClassVar[List[str]] = ["action", "actionuser", "actionuserid", "candelete", "contextid", "desca", "desccomponent", "descidentifier", "description", "grade", "gradename", "id", "note", "timecreated", "timemodified", "url", "usercompetencyid", "userdate", "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 ToolLpDataForUserCompetencySummaryInCourseResponseUsercompetencysummaryEvidenceInner 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 actionuser
        if self.actionuser:
            _dict['actionuser'] = self.actionuser.to_dict()
        # set to None if actionuserid (nullable) is None
        # and model_fields_set contains the field
        if self.actionuserid is None and "actionuserid" in self.model_fields_set:
            _dict['actionuserid'] = None

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

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

        return _dict

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

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

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

        data = {
            "action": obj.get("action") if obj.get("action") is not None else 0,
            "actionuser": CoreCompetencyCreatePlanResponseReviewer.from_dict(obj["actionuser"]) if obj.get("actionuser") is not None else None,
            "actionuserid": obj.get("actionuserid"),
            "candelete": obj.get("candelete") if obj.get("candelete") is not None else False,
            "contextid": obj.get("contextid") if obj.get("contextid") is not None else 0,
            "desca": obj.get("desca"),
            "desccomponent": obj.get("desccomponent") if obj.get("desccomponent") is not None else '',
            "descidentifier": obj.get("descidentifier") if obj.get("descidentifier") is not None else '',
            "description": obj.get("description") if obj.get("description") is not None else '',
            "grade": obj.get("grade"),
            "gradename": obj.get("gradename") if obj.get("gradename") is not None else '',
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "note": obj.get("note"),
            "timecreated": obj.get("timecreated") if obj.get("timecreated") is not None else 0,
            "timemodified": obj.get("timemodified") if obj.get("timemodified") is not None else 0,
            "url": obj.get("url"),
            "usercompetencyid": obj.get("usercompetencyid") if obj.get("usercompetencyid") is not None else 0,
            "userdate": obj.get("userdate") if obj.get("userdate") is not None else '',
            "usermodified": obj.get("usermodified") if obj.get("usermodified") is not None else 0
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


