# coding: utf-8

"""
    Moodle Webservice API

    Auto-generated OpenAPI spec for Moodle's Webservice API.

    The version of the OpenAPI document: 4.5 (Build: 20241007)
    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

class CoreCompetencyListPlanCompetenciesResponseInnerUsercompetency(BaseModel):
    """
    CoreCompetencyListPlanCompetenciesResponseInnerUsercompetency
    """ # noqa: E501
    canrequestreview: StrictBool = Field(description="canrequestreview")
    canreview: StrictBool = Field(description="canreview")
    competencyid: StrictInt = Field(description="competencyid")
    grade: Optional[StrictInt] = Field(description="grade")
    gradename: StrictStr = Field(description="gradename")
    id: StrictInt = Field(description="id")
    iscancelreviewrequestallowed: StrictBool = Field(description="iscancelreviewrequestallowed")
    isrequestreviewallowed: StrictBool = Field(description="isrequestreviewallowed")
    isstartreviewallowed: StrictBool = Field(description="isstartreviewallowed")
    isstatusidle: StrictBool = Field(description="isstatusidle")
    isstatusinreview: StrictBool = Field(description="isstatusinreview")
    isstatuswaitingforreview: StrictBool = Field(description="isstatuswaitingforreview")
    isstopreviewallowed: StrictBool = Field(description="isstopreviewallowed")
    proficiency: Optional[StrictBool] = Field(description="proficiency")
    proficiencyname: StrictStr = Field(description="proficiencyname")
    reviewer: Optional[CoreCompetencyCreatePlanResponseReviewer] = None
    reviewerid: Optional[StrictInt] = Field(description="reviewerid")
    status: StrictInt = Field(description="status")
    statusname: StrictStr = Field(description="statusname")
    timecreated: StrictInt = Field(description="timecreated")
    timemodified: StrictInt = Field(description="timemodified")
    url: StrictStr = Field(description="url")
    userid: StrictInt = Field(description="userid")
    usermodified: StrictInt = Field(description="usermodified")
    __properties: ClassVar[List[str]] = ["canrequestreview", "canreview", "competencyid", "grade", "gradename", "id", "iscancelreviewrequestallowed", "isrequestreviewallowed", "isstartreviewallowed", "isstatusidle", "isstatusinreview", "isstatuswaitingforreview", "isstopreviewallowed", "proficiency", "proficiencyname", "reviewer", "reviewerid", "status", "statusname", "timecreated", "timemodified", "url", "userid", "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 CoreCompetencyListPlanCompetenciesResponseInnerUsercompetency 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 reviewer
        if self.reviewer:
            _dict['reviewer'] = self.reviewer.to_dict()
        # 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 proficiency (nullable) is None
        # and model_fields_set contains the field
        if self.proficiency is None and "proficiency" in self.model_fields_set:
            _dict['proficiency'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "canrequestreview": obj.get("canrequestreview") if obj.get("canrequestreview") is not None else False,
            "canreview": obj.get("canreview") if obj.get("canreview") is not None else False,
            "competencyid": obj.get("competencyid") if obj.get("competencyid") is not None else 0,
            "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,
            "iscancelreviewrequestallowed": obj.get("iscancelreviewrequestallowed") if obj.get("iscancelreviewrequestallowed") is not None else False,
            "isrequestreviewallowed": obj.get("isrequestreviewallowed") if obj.get("isrequestreviewallowed") is not None else False,
            "isstartreviewallowed": obj.get("isstartreviewallowed") if obj.get("isstartreviewallowed") is not None else False,
            "isstatusidle": obj.get("isstatusidle") if obj.get("isstatusidle") is not None else False,
            "isstatusinreview": obj.get("isstatusinreview") if obj.get("isstatusinreview") is not None else False,
            "isstatuswaitingforreview": obj.get("isstatuswaitingforreview") if obj.get("isstatuswaitingforreview") is not None else False,
            "isstopreviewallowed": obj.get("isstopreviewallowed") if obj.get("isstopreviewallowed") is not None else False,
            "proficiency": obj.get("proficiency"),
            "proficiencyname": obj.get("proficiencyname") if obj.get("proficiencyname") is not None else '',
            "reviewer": CoreCompetencyCreatePlanResponseReviewer.from_dict(obj["reviewer"]) if obj.get("reviewer") is not None else None,
            "reviewerid": obj.get("reviewerid"),
            "status": obj.get("status") if obj.get("status") is not None else 0,
            "statusname": obj.get("statusname") if obj.get("statusname") is not None else '',
            "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") if obj.get("url") is not None else '',
            "userid": obj.get("userid") if obj.get("userid") is not None else 0,
            "usermodified": obj.get("usermodified") if obj.get("usermodified") is not None else 0
        })
        return _obj


