# 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 typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreMessageDataForMessageareaSearchMessagesResponseContactsInner(BaseModel):
    """
    CoreMessageDataForMessageareaSearchMessagesResponseContactsInner
    """ # noqa: E501
    conversationid: Optional[StrictInt] = Field(default=None, description="The id of the conversation")
    fullname: Optional[StrictStr] = Field(description="The user's name")
    isblocked: Optional[StrictBool] = Field(description="If the user has been blocked")
    ismessaging: Optional[StrictBool] = Field(description="If we are messaging the user")
    isonline: Optional[StrictBool] = Field(description="The user's online status")
    isread: Optional[StrictBool] = Field(description="If the user has read the message")
    lastmessage: Optional[StrictStr] = Field(description="The user's last message")
    lastmessagedate: Optional[StrictInt] = Field(default=None, description="Timestamp for last message")
    messageid: Optional[StrictInt] = Field(default=None, description="The unique search message id")
    profileimageurl: Optional[StrictStr] = Field(description="User picture URL")
    profileimageurlsmall: Optional[StrictStr] = Field(description="Small user picture URL")
    sentfromcurrentuser: Optional[StrictBool] = Field(description="Was the last message sent from the current user?")
    showonlinestatus: Optional[StrictBool] = Field(description="Show the user's online status?")
    unreadcount: Optional[StrictInt] = Field(default=None, description="The number of unread messages in this conversation")
    userid: Optional[StrictInt] = Field(description="The user's id")
    __properties: ClassVar[List[str]] = ["conversationid", "fullname", "isblocked", "ismessaging", "isonline", "isread", "lastmessage", "lastmessagedate", "messageid", "profileimageurl", "profileimageurlsmall", "sentfromcurrentuser", "showonlinestatus", "unreadcount", "userid"]

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "conversationid": obj.get("conversationid"),
            "fullname": obj.get("fullname"),
            "isblocked": obj.get("isblocked"),
            "ismessaging": obj.get("ismessaging"),
            "isonline": obj.get("isonline"),
            "isread": obj.get("isread"),
            "lastmessage": obj.get("lastmessage"),
            "lastmessagedate": obj.get("lastmessagedate"),
            "messageid": obj.get("messageid"),
            "profileimageurl": obj.get("profileimageurl"),
            "profileimageurlsmall": obj.get("profileimageurlsmall"),
            "sentfromcurrentuser": obj.get("sentfromcurrentuser"),
            "showonlinestatus": obj.get("showonlinestatus"),
            "unreadcount": obj.get("unreadcount"),
            "userid": obj.get("userid")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


