# 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_message_get_contact_requests_response_inner import CoreMessageGetContactRequestsResponseInner
from poodle_async_full.models.core_message_get_conversation_between_users_response_messages_inner import CoreMessageGetConversationBetweenUsersResponseMessagesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreMessageGetConversationBetweenUsersResponse(BaseModel):
    """
    CoreMessageGetConversationBetweenUsersResponse
    """ # noqa: E501
    candeletemessagesforallusers: Optional[StrictBool] = Field(default=False, description="If the user can delete messages in the conversation for all users")
    id: Optional[StrictInt] = Field(description="The conversation id")
    imageurl: Optional[StrictStr] = Field(default=None, description="A link to the conversation picture, if set")
    isfavourite: Optional[StrictBool] = Field(description="If the user marked this conversation as a favourite")
    ismuted: Optional[StrictBool] = Field(description="If the user muted this conversation")
    isread: Optional[StrictBool] = Field(description="If the user has read all messages in the conversation")
    membercount: Optional[StrictInt] = Field(description="Total number of conversation members")
    members: List[CoreMessageGetContactRequestsResponseInner]
    messages: List[CoreMessageGetConversationBetweenUsersResponseMessagesInner]
    name: Optional[StrictStr] = Field(default=None, description="The conversation name, if set")
    subname: Optional[StrictStr] = Field(default=None, description="A subtitle for the conversation name, if set")
    type: Optional[StrictInt] = Field(description="The type of the conversation (1=individual,2=group,3=self)")
    unreadcount: Optional[StrictInt] = Field(default=None, description="The number of unread messages in this conversation")
    __properties: ClassVar[List[str]] = ["candeletemessagesforallusers", "id", "imageurl", "isfavourite", "ismuted", "isread", "membercount", "members", "messages", "name", "subname", "type", "unreadcount"]

    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 CoreMessageGetConversationBetweenUsersResponse 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 members (list)
        _items = []
        if self.members:
            for _item_members in self.members:
                if _item_members:
                    _items.append(_item_members.to_dict())
            _dict['members'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in messages (list)
        _items = []
        if self.messages:
            for _item_messages in self.messages:
                if _item_messages:
                    _items.append(_item_messages.to_dict())
            _dict['messages'] = _items
        # 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 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 imageurl (nullable) is None
        # and model_fields_set contains the field
        if self.imageurl is None and "imageurl" in self.model_fields_set:
            _dict['imageurl'] = None

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

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

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

        return _dict

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

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

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

        data = {
            "candeletemessagesforallusers": obj.get("candeletemessagesforallusers") if obj.get("candeletemessagesforallusers") is not None else False,
            "id": obj.get("id"),
            "imageurl": obj.get("imageurl"),
            "isfavourite": obj.get("isfavourite"),
            "ismuted": obj.get("ismuted"),
            "isread": obj.get("isread"),
            "membercount": obj.get("membercount"),
            "members": [CoreMessageGetContactRequestsResponseInner.from_dict(_item) for _item in obj["members"]] if obj.get("members") is not None else None,
            "messages": [CoreMessageGetConversationBetweenUsersResponseMessagesInner.from_dict(_item) for _item in obj["messages"]] if obj.get("messages") is not None else None,
            "name": obj.get("name"),
            "subname": obj.get("subname"),
            "type": obj.get("type"),
            "unreadcount": obj.get("unreadcount")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


