# 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_mini.models.core_course_get_contents_response_inner_modules_inner_activitybadge import CoreCourseGetContentsResponseInnerModulesInnerActivitybadge
from poodle_async_mini.models.core_course_get_contents_response_inner_modules_inner_completiondata import CoreCourseGetContentsResponseInnerModulesInnerCompletiondata
from poodle_async_mini.models.core_course_get_contents_response_inner_modules_inner_contents_inner import CoreCourseGetContentsResponseInnerModulesInnerContentsInner
from poodle_async_mini.models.core_course_get_contents_response_inner_modules_inner_contentsinfo import CoreCourseGetContentsResponseInnerModulesInnerContentsinfo
from poodle_async_mini.models.core_course_get_contents_response_inner_modules_inner_dates_inner import CoreCourseGetContentsResponseInnerModulesInnerDatesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_mini.configuration import settings

class CoreCourseGetContentsResponseInnerModulesInner(BaseModel):
    """
    CoreCourseGetContentsResponseInnerModulesInner
    """ # noqa: E501
    activitybadge: Optional[CoreCourseGetContentsResponseInnerModulesInnerActivitybadge] = None
    afterlink: Optional[StrictStr] = Field(default=None, description="After link info to be displayed.")
    availability: Optional[StrictStr] = Field(default=None, description="module availability settings")
    availabilityinfo: Optional[StrictStr] = Field(default=None, description="Availability information.")
    branded: Optional[StrictBool] = Field(default=None, description="Whether the module is branded or not")
    completion: Optional[StrictInt] = Field(default=None, description="Type of completion tracking:                                         0 means none, 1 manual, 2 automatic.")
    completiondata: Optional[CoreCourseGetContentsResponseInnerModulesInnerCompletiondata] = None
    contents: Optional[List[CoreCourseGetContentsResponseInnerModulesInnerContentsInner]] = Field(default=None, description="Course contents")
    contentsinfo: Optional[CoreCourseGetContentsResponseInnerModulesInnerContentsinfo] = None
    contextid: Optional[StrictInt] = Field(default=None, description="Activity context id.")
    customdata: Optional[StrictStr] = Field(default=None, description="Custom data (JSON encoded).")
    dates: Optional[List[CoreCourseGetContentsResponseInnerModulesInnerDatesInner]] = Field(default=None, description="Course dates")
    description: Optional[StrictStr] = Field(default=None, description="activity description")
    downloadcontent: Optional[StrictInt] = Field(default=None, description="The download content value")
    groupmode: Optional[StrictInt] = Field(default=None, description="Group mode value")
    id: Optional[StrictInt] = Field(description="activity id")
    indent: Optional[StrictInt] = Field(description="number of identation in the site")
    instance: Optional[StrictInt] = Field(default=None, description="instance id")
    modicon: Optional[StrictStr] = Field(description="activity icon url")
    modname: Optional[StrictStr] = Field(description="activity module type")
    modplural: Optional[StrictStr] = Field(description="activity module plural name")
    name: Optional[StrictStr] = Field(description="activity module name")
    noviewlink: Optional[StrictBool] = Field(default=None, description="Whether the module has no view page")
    onclick: Optional[StrictStr] = Field(default=None, description="Onclick action.")
    purpose: Optional[StrictStr] = Field(description="the module purpose")
    url: Optional[StrictStr] = Field(default=None, description="activity url")
    uservisible: Optional[StrictBool] = Field(default=None, description="Is the module visible for the user?")
    visible: Optional[StrictInt] = Field(default=None, description="is the module visible")
    visibleoncoursepage: Optional[StrictInt] = Field(default=None, description="is the module visible on course page")
    __properties: ClassVar[List[str]] = ["activitybadge", "afterlink", "availability", "availabilityinfo", "branded", "completion", "completiondata", "contents", "contentsinfo", "contextid", "customdata", "dates", "description", "downloadcontent", "groupmode", "id", "indent", "instance", "modicon", "modname", "modplural", "name", "noviewlink", "onclick", "purpose", "url", "uservisible", "visible", "visibleoncoursepage"]

    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 CoreCourseGetContentsResponseInnerModulesInner 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 activitybadge
        if self.activitybadge:
            _dict['activitybadge'] = self.activitybadge.to_dict()
        # override the default output from pydantic by calling `to_dict()` of completiondata
        if self.completiondata:
            _dict['completiondata'] = self.completiondata.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in contents (list)
        _items = []
        if self.contents:
            for _item_contents in self.contents:
                if _item_contents:
                    _items.append(_item_contents.to_dict())
            _dict['contents'] = _items
        # override the default output from pydantic by calling `to_dict()` of contentsinfo
        if self.contentsinfo:
            _dict['contentsinfo'] = self.contentsinfo.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in dates (list)
        _items = []
        if self.dates:
            for _item_dates in self.dates:
                if _item_dates:
                    _items.append(_item_dates.to_dict())
            _dict['dates'] = _items
        # set to None if afterlink (nullable) is None
        # and model_fields_set contains the field
        if self.afterlink is None and "afterlink" in self.model_fields_set:
            _dict['afterlink'] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "activitybadge": CoreCourseGetContentsResponseInnerModulesInnerActivitybadge.from_dict(obj["activitybadge"]) if obj.get("activitybadge") is not None else None,
            "afterlink": obj.get("afterlink"),
            "availability": obj.get("availability"),
            "availabilityinfo": obj.get("availabilityinfo"),
            "branded": obj.get("branded"),
            "completion": obj.get("completion"),
            "completiondata": CoreCourseGetContentsResponseInnerModulesInnerCompletiondata.from_dict(obj["completiondata"]) if obj.get("completiondata") is not None else None,
            "contents": [CoreCourseGetContentsResponseInnerModulesInnerContentsInner.from_dict(_item) for _item in obj["contents"]] if obj.get("contents") is not None else None,
            "contentsinfo": CoreCourseGetContentsResponseInnerModulesInnerContentsinfo.from_dict(obj["contentsinfo"]) if obj.get("contentsinfo") is not None else None,
            "contextid": obj.get("contextid"),
            "customdata": obj.get("customdata"),
            "dates": [CoreCourseGetContentsResponseInnerModulesInnerDatesInner.from_dict(_item) for _item in obj["dates"]] if obj.get("dates") is not None else None,
            "description": obj.get("description"),
            "downloadcontent": obj.get("downloadcontent"),
            "groupmode": obj.get("groupmode"),
            "id": obj.get("id"),
            "indent": obj.get("indent"),
            "instance": obj.get("instance"),
            "modicon": obj.get("modicon"),
            "modname": obj.get("modname"),
            "modplural": obj.get("modplural"),
            "name": obj.get("name"),
            "noviewlink": obj.get("noviewlink"),
            "onclick": obj.get("onclick"),
            "purpose": obj.get("purpose"),
            "url": obj.get("url"),
            "uservisible": obj.get("uservisible"),
            "visible": obj.get("visible"),
            "visibleoncoursepage": obj.get("visibleoncoursepage")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


