# 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 ModForumGetForumDiscussionsResponseDiscussionsInner(BaseModel):
    """
    post
    """ # noqa: E501
    attachment: Optional[StrictStr] = Field(description="Has attachments?")
    attachments: Optional[List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner]] = Field(default=None, description="attachments")
    canfavourite: Optional[StrictBool] = Field(description="Can the user star the discussion")
    canlock: Optional[StrictBool] = Field(description="Can the user lock the discussion")
    canreply: Optional[StrictBool] = Field(description="Can the user reply to the discussion")
    created: Optional[StrictInt] = Field(description="Creation time")
    discussion: Optional[StrictInt] = Field(description="Discussion id")
    groupid: Optional[StrictInt] = Field(description="Group id")
    id: Optional[StrictInt] = Field(description="Post id")
    locked: Optional[StrictBool] = Field(description="Is the discussion locked")
    mailed: Optional[StrictInt] = Field(description="Mailed?")
    mailnow: Optional[StrictInt] = Field(description="Mail now?")
    message: Optional[StrictStr] = Field(description="The post message")
    messageformat: Optional[StrictInt] = Field(description="message format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    messageinlinefiles: Optional[List[CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner]] = Field(default=None, description="post message inline files")
    messagetrust: Optional[StrictInt] = Field(description="Can we trust?")
    modified: Optional[StrictInt] = Field(description="Time modified")
    name: Optional[StrictStr] = Field(description="Discussion name")
    numreplies: Optional[StrictInt] = Field(description="The number of replies in the discussion")
    numunread: Optional[StrictInt] = Field(description="The number of unread discussions.")
    parent: Optional[StrictInt] = Field(description="Parent id")
    pinned: Optional[StrictBool] = Field(description="Is the discussion pinned")
    starred: Optional[StrictBool] = Field(description="Is the discussion starred")
    subject: Optional[StrictStr] = Field(description="The post subject")
    timeend: Optional[StrictInt] = Field(description="Time discussion ends")
    timemodified: Optional[StrictInt] = Field(description="Time modified")
    timestart: Optional[StrictInt] = Field(description="Time discussion can start")
    totalscore: Optional[StrictInt] = Field(description="The post message total score")
    userfullname: Optional[StrictStr] = Field(description="Post author full name")
    userid: Optional[StrictInt] = Field(description="User who started the discussion id")
    usermodified: Optional[StrictInt] = Field(description="The id of the user who last modified")
    usermodifiedfullname: Optional[StrictStr] = Field(description="Post modifier full name")
    usermodifiedpictureurl: Optional[StrictStr] = Field(description="Post modifier picture.")
    userpictureurl: Optional[StrictStr] = Field(description="Post author picture.")
    __properties: ClassVar[List[str]] = ["attachment", "attachments", "canfavourite", "canlock", "canreply", "created", "discussion", "groupid", "id", "locked", "mailed", "mailnow", "message", "messageformat", "messageinlinefiles", "messagetrust", "modified", "name", "numreplies", "numunread", "parent", "pinned", "starred", "subject", "timeend", "timemodified", "timestart", "totalscore", "userfullname", "userid", "usermodified", "usermodifiedfullname", "usermodifiedpictureurl", "userpictureurl"]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        # 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

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

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

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

        return _dict

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

        relaxed = settings.relaxe_all_models or "ModForumGetForumDiscussionsResponseDiscussionsInner" 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"),
            "attachments": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["attachments"]] if obj.get("attachments") is not None else None,
            "canfavourite": obj.get("canfavourite"),
            "canlock": obj.get("canlock"),
            "canreply": obj.get("canreply"),
            "created": obj.get("created"),
            "discussion": obj.get("discussion"),
            "groupid": obj.get("groupid"),
            "id": obj.get("id"),
            "locked": obj.get("locked"),
            "mailed": obj.get("mailed"),
            "mailnow": obj.get("mailnow"),
            "message": obj.get("message"),
            "messageformat": obj.get("messageformat"),
            "messageinlinefiles": [CoreBlockGetCourseBlocksResponseBlocksInnerContentsFilesInner.from_dict(_item) for _item in obj["messageinlinefiles"]] if obj.get("messageinlinefiles") is not None else None,
            "messagetrust": obj.get("messagetrust"),
            "modified": obj.get("modified"),
            "name": obj.get("name"),
            "numreplies": obj.get("numreplies"),
            "numunread": obj.get("numunread"),
            "parent": obj.get("parent"),
            "pinned": obj.get("pinned"),
            "starred": obj.get("starred"),
            "subject": obj.get("subject"),
            "timeend": obj.get("timeend"),
            "timemodified": obj.get("timemodified"),
            "timestart": obj.get("timestart"),
            "totalscore": obj.get("totalscore"),
            "userfullname": obj.get("userfullname"),
            "userid": obj.get("userid"),
            "usermodified": obj.get("usermodified"),
            "usermodifiedfullname": obj.get("usermodifiedfullname"),
            "usermodifiedpictureurl": obj.get("usermodifiedpictureurl"),
            "userpictureurl": obj.get("userpictureurl")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


