# 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
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.core_competency_list_competencies_in_template_response_inner import CoreCompetencyListCompetenciesInTemplateResponseInner
from poodle_async_full.models.core_competency_list_course_competencies_response_inner_coursecompetency import CoreCompetencyListCourseCompetenciesResponseInnerCoursecompetency
from poodle_async_full.models.core_competency_list_user_plans_response_inner import CoreCompetencyListUserPlansResponseInner
from poodle_async_full.models.report_competency_data_for_report_response_usercompetencies_inner_competency_comppath import ReportCompetencyDataForReportResponseUsercompetenciesInnerCompetencyComppath
from poodle_async_full.models.report_competency_data_for_report_response_usercompetencies_inner_usercompetencycourse import ReportCompetencyDataForReportResponseUsercompetenciesInnerUsercompetencycourse
from poodle_async_full.models.tool_lp_data_for_course_competencies_page_response_competencies_inner_coursemodules_inner import ToolLpDataForCourseCompetenciesPageResponseCompetenciesInnerCoursemodulesInner
from poodle_async_full.models.tool_lp_data_for_course_competencies_page_response_competencies_inner_ruleoutcomeoptions_inner import ToolLpDataForCourseCompetenciesPageResponseCompetenciesInnerRuleoutcomeoptionsInner
from typing import Optional, Set
from typing_extensions import Self

class ToolLpDataForCourseCompetenciesPageResponseCompetenciesInner(BaseModel):
    """
    ToolLpDataForCourseCompetenciesPageResponseCompetenciesInner
    """ # noqa: E501
    competency: CoreCompetencyListCompetenciesInTemplateResponseInner
    comppath: ReportCompetencyDataForReportResponseUsercompetenciesInnerCompetencyComppath
    coursecompetency: CoreCompetencyListCourseCompetenciesResponseInnerCoursecompetency
    coursemodules: List[ToolLpDataForCourseCompetenciesPageResponseCompetenciesInnerCoursemodulesInner]
    plans: List[CoreCompetencyListUserPlansResponseInner]
    ruleoutcomeoptions: List[ToolLpDataForCourseCompetenciesPageResponseCompetenciesInnerRuleoutcomeoptionsInner]
    usercompetencycourse: Optional[ReportCompetencyDataForReportResponseUsercompetenciesInnerUsercompetencycourse] = None
    __properties: ClassVar[List[str]] = ["competency", "comppath", "coursecompetency", "coursemodules", "plans", "ruleoutcomeoptions", "usercompetencycourse"]

    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 ToolLpDataForCourseCompetenciesPageResponseCompetenciesInner 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 competency
        if self.competency:
            _dict['competency'] = self.competency.to_dict()
        # override the default output from pydantic by calling `to_dict()` of comppath
        if self.comppath:
            _dict['comppath'] = self.comppath.to_dict()
        # override the default output from pydantic by calling `to_dict()` of coursecompetency
        if self.coursecompetency:
            _dict['coursecompetency'] = self.coursecompetency.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in coursemodules (list)
        _items = []
        if self.coursemodules:
            for _item_coursemodules in self.coursemodules:
                if _item_coursemodules:
                    _items.append(_item_coursemodules.to_dict())
            _dict['coursemodules'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in plans (list)
        _items = []
        if self.plans:
            for _item_plans in self.plans:
                if _item_plans:
                    _items.append(_item_plans.to_dict())
            _dict['plans'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in ruleoutcomeoptions (list)
        _items = []
        if self.ruleoutcomeoptions:
            for _item_ruleoutcomeoptions in self.ruleoutcomeoptions:
                if _item_ruleoutcomeoptions:
                    _items.append(_item_ruleoutcomeoptions.to_dict())
            _dict['ruleoutcomeoptions'] = _items
        # override the default output from pydantic by calling `to_dict()` of usercompetencycourse
        if self.usercompetencycourse:
            _dict['usercompetencycourse'] = self.usercompetencycourse.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "competency": CoreCompetencyListCompetenciesInTemplateResponseInner.from_dict(obj["competency"]) if obj.get("competency") is not None else None,
            "comppath": ReportCompetencyDataForReportResponseUsercompetenciesInnerCompetencyComppath.from_dict(obj["comppath"]) if obj.get("comppath") is not None else None,
            "coursecompetency": CoreCompetencyListCourseCompetenciesResponseInnerCoursecompetency.from_dict(obj["coursecompetency"]) if obj.get("coursecompetency") is not None else None,
            "coursemodules": [ToolLpDataForCourseCompetenciesPageResponseCompetenciesInnerCoursemodulesInner.from_dict(_item) for _item in obj["coursemodules"]] if obj.get("coursemodules") is not None else None,
            "plans": [CoreCompetencyListUserPlansResponseInner.from_dict(_item) for _item in obj["plans"]] if obj.get("plans") is not None else None,
            "ruleoutcomeoptions": [ToolLpDataForCourseCompetenciesPageResponseCompetenciesInnerRuleoutcomeoptionsInner.from_dict(_item) for _item in obj["ruleoutcomeoptions"]] if obj.get("ruleoutcomeoptions") is not None else None,
            "usercompetencycourse": ReportCompetencyDataForReportResponseUsercompetenciesInnerUsercompetencycourse.from_dict(obj["usercompetencycourse"]) if obj.get("usercompetencycourse") is not None else None
        })
        return _obj


