# coding: utf-8

"""
    Moodle Webservice API

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

    The version of the OpenAPI document: 5.0.2 (Build: 20250811)
    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.tool_lp_data_for_course_competencies_page_response_competencies_inner import ToolLpDataForCourseCompetenciesPageResponseCompetenciesInner
from poodle_async_full.models.tool_lp_data_for_course_competencies_page_response_settings import ToolLpDataForCourseCompetenciesPageResponseSettings
from poodle_async_full.models.tool_lp_data_for_course_competencies_page_response_statistics import ToolLpDataForCourseCompetenciesPageResponseStatistics
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ToolLpDataForCourseCompetenciesPageResponse(BaseModel):
    """
    ToolLpDataForCourseCompetenciesPageResponse
    """ # noqa: E501
    canconfigurecoursecompetencies: Optional[StrictBool] = Field(description="User can configure course competency settings")
    cangradecompetencies: Optional[StrictBool] = Field(description="User can grade competencies.")
    canmanagecompetencyframeworks: Optional[StrictBool] = Field(description="User can manage competency frameworks")
    canmanagecoursecompetencies: Optional[StrictBool] = Field(description="User can manage linked course competencies")
    competencies: List[ToolLpDataForCourseCompetenciesPageResponseCompetenciesInner]
    courseid: Optional[StrictInt] = Field(description="The current course id")
    gradableuserid: Optional[StrictInt] = Field(default=None, description="Current user id, if the user is a gradable user.")
    manageurl: Optional[StrictStr] = Field(description="Url to the manage competencies page.")
    pagecontextid: Optional[StrictInt] = Field(description="The current page context ID.")
    pluginbaseurl: Optional[StrictStr] = Field(description="Url to the course competencies page.")
    settings: ToolLpDataForCourseCompetenciesPageResponseSettings
    statistics: ToolLpDataForCourseCompetenciesPageResponseStatistics
    __properties: ClassVar[List[str]] = ["canconfigurecoursecompetencies", "cangradecompetencies", "canmanagecompetencyframeworks", "canmanagecoursecompetencies", "competencies", "courseid", "gradableuserid", "manageurl", "pagecontextid", "pluginbaseurl", "settings", "statistics"]

    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 ToolLpDataForCourseCompetenciesPageResponse 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 each item in competencies (list)
        _items = []
        if self.competencies:
            for _item_competencies in self.competencies:
                if _item_competencies:
                    _items.append(_item_competencies.to_dict())
            _dict['competencies'] = _items
        # override the default output from pydantic by calling `to_dict()` of settings
        if self.settings:
            _dict['settings'] = self.settings.to_dict()
        # override the default output from pydantic by calling `to_dict()` of statistics
        if self.statistics:
            _dict['statistics'] = self.statistics.to_dict()
        # set to None if canconfigurecoursecompetencies (nullable) is None
        # and model_fields_set contains the field
        if self.canconfigurecoursecompetencies is None and "canconfigurecoursecompetencies" in self.model_fields_set:
            _dict['canconfigurecoursecompetencies'] = None

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "canconfigurecoursecompetencies": obj.get("canconfigurecoursecompetencies"),
            "cangradecompetencies": obj.get("cangradecompetencies"),
            "canmanagecompetencyframeworks": obj.get("canmanagecompetencyframeworks"),
            "canmanagecoursecompetencies": obj.get("canmanagecoursecompetencies"),
            "competencies": [ToolLpDataForCourseCompetenciesPageResponseCompetenciesInner.from_dict(_item) for _item in obj["competencies"]] if obj.get("competencies") is not None else None,
            "courseid": obj.get("courseid"),
            "gradableuserid": obj.get("gradableuserid"),
            "manageurl": obj.get("manageurl"),
            "pagecontextid": obj.get("pagecontextid"),
            "pluginbaseurl": obj.get("pluginbaseurl"),
            "settings": ToolLpDataForCourseCompetenciesPageResponseSettings.from_dict(obj["settings"]) if obj.get("settings") is not None else None,
            "statistics": ToolLpDataForCourseCompetenciesPageResponseStatistics.from_dict(obj["statistics"]) if obj.get("statistics") is not None else None
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


