# coding: utf-8

"""
    Moodle Webservice API

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

    The version of the OpenAPI document: 4.5.7 (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_mini.models.core_course_get_contents_response_inner_modules_inner import CoreCourseGetContentsResponseInnerModulesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_mini.configuration import settings

class CoreCourseGetContentsResponseInner(BaseModel):
    """
    CoreCourseGetContentsResponseInner
    """ # noqa: E501
    availabilityinfo: Optional[StrictStr] = Field(default=None, description="Availability information.")
    component: Optional[StrictStr] = Field(default=None, description="The delegate component of this section if any.")
    hiddenbynumsections: Optional[StrictInt] = Field(default=None, description="Whether is a section hidden in the course format")
    id: Optional[StrictInt] = Field(description="Section ID")
    itemid: Optional[StrictInt] = Field(default=None, description="The optional item id delegate component can use to identify its instance.")
    modules: List[CoreCourseGetContentsResponseInnerModulesInner] = Field(description="list of module")
    name: Optional[StrictStr] = Field(description="Section name")
    section: Optional[StrictInt] = Field(default=None, description="Section number inside the course")
    summary: Optional[StrictStr] = Field(description="Section description")
    summaryformat: Optional[StrictInt] = Field(description="summary format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    uservisible: Optional[StrictBool] = Field(default=None, description="Is the section visible for the user?")
    visible: Optional[StrictInt] = Field(default=None, description="is the section visible")
    __properties: ClassVar[List[str]] = ["availabilityinfo", "component", "hiddenbynumsections", "id", "itemid", "modules", "name", "section", "summary", "summaryformat", "uservisible", "visible"]

    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 CoreCourseGetContentsResponseInner 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 modules (list)
        _items = []
        if self.modules:
            for _item_modules in self.modules:
                if _item_modules:
                    _items.append(_item_modules.to_dict())
            _dict['modules'] = _items
        # 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 component (nullable) is None
        # and model_fields_set contains the field
        if self.component is None and "component" in self.model_fields_set:
            _dict['component'] = None

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

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

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

        return _dict

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

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

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

        data = {
            "availabilityinfo": obj.get("availabilityinfo"),
            "component": obj.get("component"),
            "hiddenbynumsections": obj.get("hiddenbynumsections"),
            "id": obj.get("id"),
            "itemid": obj.get("itemid"),
            "modules": [CoreCourseGetContentsResponseInnerModulesInner.from_dict(_item) for _item in obj["modules"]] if obj.get("modules") is not None else None,
            "name": obj.get("name"),
            "section": obj.get("section"),
            "summary": obj.get("summary"),
            "summaryformat": obj.get("summaryformat"),
            "uservisible": obj.get("uservisible"),
            "visible": obj.get("visible")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


