# 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_competency_read_user_evidence_response_files_inner import CoreCompetencyReadUserEvidenceResponseFilesInner
from poodle_async_full.models.mod_forum_add_discussion_post_response_post_attachments_inner import ModForumAddDiscussionPostResponsePostAttachmentsInner
from poodle_async_full.models.mod_forum_add_discussion_post_response_post_author import ModForumAddDiscussionPostResponsePostAuthor
from poodle_async_full.models.mod_forum_add_discussion_post_response_post_capabilities import ModForumAddDiscussionPostResponsePostCapabilities
from poodle_async_full.models.mod_forum_add_discussion_post_response_post_html import ModForumAddDiscussionPostResponsePostHtml
from poodle_async_full.models.mod_forum_add_discussion_post_response_post_tags_inner import ModForumAddDiscussionPostResponsePostTagsInner
from poodle_async_full.models.mod_forum_add_discussion_post_response_post_urls import ModForumAddDiscussionPostResponsePostUrls
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModForumAddDiscussionPostResponsePost(BaseModel):
    """
    ModForumAddDiscussionPostResponsePost
    """ # noqa: E501
    attachments: List[ModForumAddDiscussionPostResponsePostAttachmentsInner] = Field(description="attachments")
    author: ModForumAddDiscussionPostResponsePostAuthor
    capabilities: ModForumAddDiscussionPostResponsePostCapabilities
    charcount: Optional[StrictInt] = Field(default=None, description="charcount")
    discussionid: StrictInt = Field(description="discussionid")
    hasparent: StrictBool = Field(description="hasparent")
    haswordcount: StrictBool = Field(description="haswordcount")
    html: Optional[ModForumAddDiscussionPostResponsePostHtml] = None
    id: StrictInt = Field(description="id")
    isdeleted: StrictBool = Field(description="isdeleted")
    isprivatereply: StrictBool = Field(description="isprivatereply")
    message: StrictStr = Field(description="message")
    messageformat: Optional[StrictInt] = Field(description="message format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    messageinlinefiles: Optional[List[CoreCompetencyReadUserEvidenceResponseFilesInner]] = Field(default=None, description="messageinlinefiles")
    parentid: Optional[StrictInt] = Field(default=None, description="parentid")
    replysubject: StrictStr = Field(description="replysubject")
    subject: StrictStr = Field(description="subject")
    tags: Optional[List[ModForumAddDiscussionPostResponsePostTagsInner]] = Field(default=None, description="tags")
    timecreated: Optional[StrictInt] = Field(description="timecreated")
    timemodified: Optional[StrictInt] = Field(description="timemodified")
    unread: Optional[StrictBool] = Field(default=None, description="unread")
    urls: Optional[ModForumAddDiscussionPostResponsePostUrls] = None
    wordcount: Optional[StrictInt] = Field(default=None, description="wordcount")
    __properties: ClassVar[List[str]] = ["attachments", "author", "capabilities", "charcount", "discussionid", "hasparent", "haswordcount", "html", "id", "isdeleted", "isprivatereply", "message", "messageformat", "messageinlinefiles", "parentid", "replysubject", "subject", "tags", "timecreated", "timemodified", "unread", "urls", "wordcount"]

    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 ModForumAddDiscussionPostResponsePost 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 attachments (list)
        _items = []
        if self.attachments:
            for _item_attachments in self.attachments:
                if _item_attachments:
                    _items.append(_item_attachments.to_dict())
            _dict['attachments'] = _items
        # override the default output from pydantic by calling `to_dict()` of author
        if self.author:
            _dict['author'] = self.author.to_dict()
        # override the default output from pydantic by calling `to_dict()` of capabilities
        if self.capabilities:
            _dict['capabilities'] = self.capabilities.to_dict()
        # override the default output from pydantic by calling `to_dict()` of html
        if self.html:
            _dict['html'] = self.html.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in messageinlinefiles (list)
        _items = []
        if self.messageinlinefiles:
            for _item_messageinlinefiles in self.messageinlinefiles:
                if _item_messageinlinefiles:
                    _items.append(_item_messageinlinefiles.to_dict())
            _dict['messageinlinefiles'] = _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
        # override the default output from pydantic by calling `to_dict()` of urls
        if self.urls:
            _dict['urls'] = self.urls.to_dict()
        # set to None if charcount (nullable) is None
        # and model_fields_set contains the field
        if self.charcount is None and "charcount" in self.model_fields_set:
            _dict['charcount'] = None

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

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

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

        return _dict

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

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

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

        data = {
            "attachments": [ModForumAddDiscussionPostResponsePostAttachmentsInner.from_dict(_item) for _item in obj["attachments"]] if obj.get("attachments") is not None else None,
            "author": ModForumAddDiscussionPostResponsePostAuthor.from_dict(obj["author"]) if obj.get("author") is not None else None,
            "capabilities": ModForumAddDiscussionPostResponsePostCapabilities.from_dict(obj["capabilities"]) if obj.get("capabilities") is not None else None,
            "charcount": obj.get("charcount"),
            "discussionid": obj.get("discussionid") if obj.get("discussionid") is not None else 0,
            "hasparent": obj.get("hasparent") if obj.get("hasparent") is not None else False,
            "haswordcount": obj.get("haswordcount") if obj.get("haswordcount") is not None else False,
            "html": ModForumAddDiscussionPostResponsePostHtml.from_dict(obj["html"]) if obj.get("html") is not None else None,
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "isdeleted": obj.get("isdeleted") if obj.get("isdeleted") is not None else False,
            "isprivatereply": obj.get("isprivatereply") if obj.get("isprivatereply") is not None else False,
            "message": obj.get("message") if obj.get("message") is not None else '',
            "messageformat": obj.get("messageformat"),
            "messageinlinefiles": [CoreCompetencyReadUserEvidenceResponseFilesInner.from_dict(_item) for _item in obj["messageinlinefiles"]] if obj.get("messageinlinefiles") is not None else None,
            "parentid": obj.get("parentid"),
            "replysubject": obj.get("replysubject") if obj.get("replysubject") is not None else '',
            "subject": obj.get("subject") if obj.get("subject") is not None else '',
            "tags": [ModForumAddDiscussionPostResponsePostTagsInner.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"),
            "unread": obj.get("unread"),
            "urls": ModForumAddDiscussionPostResponsePostUrls.from_dict(obj["urls"]) if obj.get("urls") is not None else None,
            "wordcount": obj.get("wordcount")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


