# 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_contents_inner_tags_inner import CoreCourseGetContentsResponseInnerModulesInnerContentsInnerTagsInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_mini.configuration import settings

class CoreCourseGetContentsResponseInnerModulesInnerContentsInner(BaseModel):
    """
    CoreCourseGetContentsResponseInnerModulesInnerContentsInner
    """ # noqa: E501
    author: Optional[StrictStr] = Field(description="Content owner")
    content: Optional[StrictStr] = Field(default=None, description="Raw content, will be used when type is content")
    filename: Optional[StrictStr] = Field(description="filename")
    filepath: Optional[StrictStr] = Field(description="filepath")
    filesize: Optional[StrictInt] = Field(description="filesize")
    fileurl: Optional[StrictStr] = Field(default=None, description="downloadable file url")
    isexternalfile: Optional[StrictBool] = Field(default=None, description="Whether is an external file.")
    license: Optional[StrictStr] = Field(description="Content license")
    mimetype: Optional[StrictStr] = Field(default=None, description="File mime type.")
    repositorytype: Optional[StrictStr] = Field(default=None, description="The repository type for external files.")
    sortorder: Optional[StrictInt] = Field(description="Content sort order")
    tags: Optional[List[CoreCourseGetContentsResponseInnerModulesInnerContentsInnerTagsInner]] = Field(default=None, description="Tags")
    timecreated: Optional[StrictInt] = Field(description="Time created")
    timemodified: Optional[StrictInt] = Field(description="Time modified")
    type: Optional[StrictStr] = Field(description="a file or a folder or external link")
    userid: Optional[StrictInt] = Field(description="User who added this content to moodle")
    __properties: ClassVar[List[str]] = ["author", "content", "filename", "filepath", "filesize", "fileurl", "isexternalfile", "license", "mimetype", "repositorytype", "sortorder", "tags", "timecreated", "timemodified", "type", "userid"]

    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 CoreCourseGetContentsResponseInnerModulesInnerContentsInner 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 tags (list)
        _items = []
        if self.tags:
            for _item_tags in self.tags:
                if _item_tags:
                    _items.append(_item_tags.to_dict())
            _dict['tags'] = _items
        # set to None if author (nullable) is None
        # and model_fields_set contains the field
        if self.author is None and "author" in self.model_fields_set:
            _dict['author'] = None

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "author": obj.get("author"),
            "content": obj.get("content"),
            "filename": obj.get("filename"),
            "filepath": obj.get("filepath"),
            "filesize": obj.get("filesize"),
            "fileurl": obj.get("fileurl"),
            "isexternalfile": obj.get("isexternalfile"),
            "license": obj.get("license"),
            "mimetype": obj.get("mimetype"),
            "repositorytype": obj.get("repositorytype"),
            "sortorder": obj.get("sortorder"),
            "tags": [CoreCourseGetContentsResponseInnerModulesInnerContentsInnerTagsInner.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None,
            "timecreated": obj.get("timecreated"),
            "timemodified": obj.get("timemodified"),
            "type": obj.get("type"),
            "userid": obj.get("userid")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


