# coding: utf-8

"""
    Moodle Webservice API

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

    The version of the OpenAPI document: 4.5 (Build: 20241007)
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.core_blog_get_entries_response_entries_inner_attachmentfiles_inner import CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner
from typing import Optional, Set
from typing_extensions import Self

class ModDataGetEntriesResponseEntriesInnerContentsInner(BaseModel):
    """
    ModDataGetEntriesResponseEntriesInnerContentsInner
    """ # noqa: E501
    content: Optional[StrictStr] = Field(description="Contents.")
    content1: Optional[StrictStr] = Field(description="Contents.")
    content2: Optional[StrictStr] = Field(description="Contents.")
    content3: Optional[StrictStr] = Field(description="Contents.")
    content4: Optional[StrictStr] = Field(description="Contents.")
    fieldid: StrictInt = Field(description="The field type of the content.")
    files: Optional[List[CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner]] = Field(default=None, description="files")
    id: StrictInt = Field(description="Content id.")
    recordid: StrictInt = Field(description="The record this content belongs to.")
    __properties: ClassVar[List[str]] = ["content", "content1", "content2", "content3", "content4", "fieldid", "files", "id", "recordid"]

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

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

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

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

        return _dict

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

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "content": obj.get("content"),
            "content1": obj.get("content1"),
            "content2": obj.get("content2"),
            "content3": obj.get("content3"),
            "content4": obj.get("content4"),
            "fieldid": obj.get("fieldid") if obj.get("fieldid") is not None else 0,
            "files": [CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None,
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "recordid": obj.get("recordid") if obj.get("recordid") is not None else 0
        })
        return _obj


