# 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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class CoreMessageSendInstantMessagesResponseInner(BaseModel):
    """
    CoreMessageSendInstantMessagesResponseInner
    """ # noqa: E501
    candeletemessagesforallusers: Optional[StrictBool] = Field(default=False, description="If the user can delete messages in the conversation for all users")
    clientmsgid: Optional[StrictStr] = Field(default=None, description="your own id for the message")
    conversationid: Optional[StrictInt] = Field(default=None, description="The conversation id for this message")
    errormessage: Optional[StrictStr] = Field(default=None, description="error message - if it failed")
    msgid: Optional[StrictInt] = Field(description="test this to know if it succeeds:  id of the created message if it succeeded, -1 when failed")
    text: Optional[StrictStr] = Field(default=None, description="The text of the message")
    timecreated: Optional[StrictInt] = Field(default=None, description="The timecreated timestamp for the message")
    useridfrom: Optional[StrictInt] = Field(default=None, description="The user id who sent the message")
    __properties: ClassVar[List[str]] = ["candeletemessagesforallusers", "clientmsgid", "conversationid", "errormessage", "msgid", "text", "timecreated", "useridfrom"]

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "candeletemessagesforallusers": obj.get("candeletemessagesforallusers") if obj.get("candeletemessagesforallusers") is not None else False,
            "clientmsgid": obj.get("clientmsgid"),
            "conversationid": obj.get("conversationid"),
            "errormessage": obj.get("errormessage"),
            "msgid": obj.get("msgid"),
            "text": obj.get("text"),
            "timecreated": obj.get("timecreated"),
            "useridfrom": obj.get("useridfrom")
        })
        return _obj


