# coding: utf-8

"""
    Moodle Webservice API

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

    The version of the OpenAPI document: 5.0.3 (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_full.models.core_block_get_course_blocks_response_blocks_inner_contents_files_inner import CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModFolderGetFoldersByCoursesResponseFoldersInner(BaseModel):
    """
    ModFolderGetFoldersByCoursesResponseFoldersInner
    """ # noqa: E501
    course: Optional[StrictInt] = Field(description="Course id")
    coursemodule: Optional[StrictInt] = Field(description="Course module id")
    display: Optional[StrictInt] = Field(description="Display type of folder contents on a separate page or inline")
    forcedownload: Optional[StrictInt] = Field(description="Whether file download is forced")
    groupingid: Optional[StrictInt] = Field(default=None, description="Group id")
    groupmode: Optional[StrictInt] = Field(default=None, description="Group mode")
    id: Optional[StrictInt] = Field(description="Activity instance id")
    intro: Optional[StrictStr] = Field(description="Activity introduction")
    introfiles: Optional[List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner]] = Field(default=None, description="Files in the introduction")
    introformat: Optional[StrictInt] = Field(description="intro format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    lang: Optional[StrictStr] = Field(default=None, description="Forced activity language")
    name: Optional[StrictStr] = Field(description="Activity name")
    revision: Optional[StrictInt] = Field(description="Incremented when after each file changes, to avoid cache")
    section: Optional[StrictInt] = Field(default=None, description="Course section id")
    showdownloadfolder: Optional[StrictInt] = Field(description="Whether to show the download folder button")
    showexpanded: Optional[StrictInt] = Field(description="1 = expanded, 0 = collapsed for sub-folders")
    timemodified: Optional[StrictInt] = Field(description="Last time the folder was modified")
    visible: Optional[StrictBool] = Field(default=None, description="Visible")
    __properties: ClassVar[List[str]] = ["course", "coursemodule", "display", "forcedownload", "groupingid", "groupmode", "id", "intro", "introfiles", "introformat", "lang", "name", "revision", "section", "showdownloadfolder", "showexpanded", "timemodified", "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 ModFolderGetFoldersByCoursesResponseFoldersInner 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 introfiles (list)
        _items = []
        if self.introfiles:
            for _item_introfiles in self.introfiles:
                if _item_introfiles:
                    _items.append(_item_introfiles.to_dict())
            _dict['introfiles'] = _items
        # set to None if course (nullable) is None
        # and model_fields_set contains the field
        if self.course is None and "course" in self.model_fields_set:
            _dict['course'] = None

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

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

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

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

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

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

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

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

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

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

        data = {
            "course": obj.get("course"),
            "coursemodule": obj.get("coursemodule"),
            "display": obj.get("display"),
            "forcedownload": obj.get("forcedownload"),
            "groupingid": obj.get("groupingid"),
            "groupmode": obj.get("groupmode"),
            "id": obj.get("id"),
            "intro": obj.get("intro"),
            "introfiles": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["introfiles"]] if obj.get("introfiles") is not None else None,
            "introformat": obj.get("introformat"),
            "lang": obj.get("lang"),
            "name": obj.get("name"),
            "revision": obj.get("revision"),
            "section": obj.get("section"),
            "showdownloadfolder": obj.get("showdownloadfolder"),
            "showexpanded": obj.get("showexpanded"),
            "timemodified": obj.get("timemodified"),
            "visible": obj.get("visible")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


