# 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_blog_get_entries_response_entries_inner_attachmentfiles_inner import CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner
from poodle_async_full.models.core_blog_get_entries_response_entries_inner_tags_inner import CoreBlogGetEntriesResponseEntriesInnerTagsInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreBlogGetEntriesResponseEntriesInner(BaseModel):
    """
    CoreBlogGetEntriesResponseEntriesInner
    """ # noqa: E501
    attachment: Optional[StrictStr] = Field(description="Post atachment.")
    attachmentfiles: Optional[List[CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner]] = Field(default=None, description="attachmentfiles")
    canedit: Optional[StrictBool] = Field(default=False, description="Whether the user can edit the post.")
    content: Optional[StrictStr] = Field(description="Post content.")
    courseid: StrictInt = Field(description="Course where the post was created.")
    coursemoduleid: StrictInt = Field(description="Course module id where the post was created.")
    created: StrictInt = Field(description="When it was created.")
    format: StrictInt = Field(description="Post content format.")
    groupid: StrictInt = Field(description="Group post was created for.")
    id: Optional[StrictInt] = Field(description="Post/entry id.")
    lastmodified: StrictInt = Field(description="When it was last modified.")
    module: StrictStr = Field(description="Where it was published the post (blog, blog_external...).")
    moduleid: StrictInt = Field(description="Module id where the post was created (not used anymore).")
    publishstate: StrictStr = Field(description="Post publish state.")
    rating: StrictInt = Field(description="Post rating.")
    subject: StrictStr = Field(description="Post subject.")
    summary: Optional[StrictStr] = Field(description="Post summary.")
    summaryfiles: List[CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner] = Field(description="summaryfiles")
    summaryformat: Optional[StrictInt] = Field(default=0, description="summary format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    tags: Optional[List[CoreBlogGetEntriesResponseEntriesInnerTagsInner]] = Field(default=None, description="Tags.")
    uniquehash: StrictStr = Field(description="Post unique hash.")
    userid: StrictInt = Field(description="Post author.")
    usermodified: Optional[StrictInt] = Field(description="User that updated the post.")
    __properties: ClassVar[List[str]] = ["attachment", "attachmentfiles", "canedit", "content", "courseid", "coursemoduleid", "created", "format", "groupid", "id", "lastmodified", "module", "moduleid", "publishstate", "rating", "subject", "summary", "summaryfiles", "summaryformat", "tags", "uniquehash", "userid", "usermodified"]

    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 CoreBlogGetEntriesResponseEntriesInner 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 attachmentfiles (list)
        _items = []
        if self.attachmentfiles:
            for _item_attachmentfiles in self.attachmentfiles:
                if _item_attachmentfiles:
                    _items.append(_item_attachmentfiles.to_dict())
            _dict['attachmentfiles'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in summaryfiles (list)
        _items = []
        if self.summaryfiles:
            for _item_summaryfiles in self.summaryfiles:
                if _item_summaryfiles:
                    _items.append(_item_summaryfiles.to_dict())
            _dict['summaryfiles'] = _items
        # 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 attachment (nullable) is None
        # and model_fields_set contains the field
        if self.attachment is None and "attachment" in self.model_fields_set:
            _dict['attachment'] = 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 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 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 usermodified (nullable) is None
        # and model_fields_set contains the field
        if self.usermodified is None and "usermodified" in self.model_fields_set:
            _dict['usermodified'] = None

        return _dict

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

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

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

        data = {
            "attachment": obj.get("attachment"),
            "attachmentfiles": [CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner.from_dict(_item) for _item in obj["attachmentfiles"]] if obj.get("attachmentfiles") is not None else None,
            "canedit": obj.get("canedit") if obj.get("canedit") is not None else False,
            "content": obj.get("content"),
            "courseid": obj.get("courseid") if obj.get("courseid") is not None else 0,
            "coursemoduleid": obj.get("coursemoduleid") if obj.get("coursemoduleid") is not None else 0,
            "created": obj.get("created") if obj.get("created") is not None else 0,
            "format": obj.get("format") if obj.get("format") is not None else 0,
            "groupid": obj.get("groupid") if obj.get("groupid") is not None else 0,
            "id": obj.get("id"),
            "lastmodified": obj.get("lastmodified") if obj.get("lastmodified") is not None else 0,
            "module": obj.get("module") if obj.get("module") is not None else '',
            "moduleid": obj.get("moduleid") if obj.get("moduleid") is not None else 0,
            "publishstate": obj.get("publishstate") if obj.get("publishstate") is not None else 'draft',
            "rating": obj.get("rating") if obj.get("rating") is not None else 0,
            "subject": obj.get("subject") if obj.get("subject") is not None else '',
            "summary": obj.get("summary"),
            "summaryfiles": [CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner.from_dict(_item) for _item in obj["summaryfiles"]] if obj.get("summaryfiles") is not None else None,
            "summaryformat": obj.get("summaryformat") if obj.get("summaryformat") is not None else 0,
            "tags": [CoreBlogGetEntriesResponseEntriesInnerTagsInner.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None,
            "uniquehash": obj.get("uniquehash") if obj.get("uniquehash") is not None else '',
            "userid": obj.get("userid") if obj.get("userid") is not None else 0,
            "usermodified": obj.get("usermodified")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


