# 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_contactrequests_inner import CoreMessageGetContactRequestsResponseInnerContactrequestsInner
from poodle_async_full.models.core_message_get_contact_requests_response_inner_conversations_inner import CoreMessageGetContactRequestsResponseInnerConversationsInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreMessageGetContactRequestsResponseInner(BaseModel):
    """
    CoreMessageGetContactRequestsResponseInner
    """ # noqa: E501
    cancreatecontact: Optional[StrictBool] = Field(description="Is the user permitted to add a contact")
    canmessage: Optional[StrictBool] = Field(description="If the user can be messaged")
    canmessageevenifblocked: Optional[StrictBool] = Field(description="If the user can still message even if they get blocked")
    contactrequests: Optional[List[CoreMessageGetContactRequestsResponseInnerContactrequestsInner]] = Field(default=None, description="The contact requests")
    conversations: Optional[List[CoreMessageGetContactRequestsResponseInnerConversationsInner]] = Field(default=None, description="Conversations between users")
    fullname: Optional[StrictStr] = Field(description="The user's name")
    id: Optional[StrictInt] = Field(description="The user id")
    isblocked: Optional[StrictBool] = Field(description="If the user has been blocked")
    iscontact: Optional[StrictBool] = Field(description="Is the user a contact?")
    isdeleted: Optional[StrictBool] = Field(description="Is the user deleted?")
    isonline: Optional[StrictBool] = Field(description="The user's online status")
    profileimageurl: Optional[StrictStr] = Field(description="User picture URL")
    profileimageurlsmall: Optional[StrictStr] = Field(description="Small user picture URL")
    profileurl: Optional[StrictStr] = Field(description="The link to the user's profile page")
    requirescontact: Optional[StrictBool] = Field(description="If the user requires to be contacts")
    showonlinestatus: Optional[StrictBool] = Field(description="Show the user's online status?")
    __properties: ClassVar[List[str]] = ["cancreatecontact", "canmessage", "canmessageevenifblocked", "contactrequests", "conversations", "fullname", "id", "isblocked", "iscontact", "isdeleted", "isonline", "profileimageurl", "profileimageurlsmall", "profileurl", "requirescontact", "showonlinestatus"]

    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 CoreMessageGetContactRequestsResponseInner 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 contactrequests (list)
        _items = []
        if self.contactrequests:
            for _item_contactrequests in self.contactrequests:
                if _item_contactrequests:
                    _items.append(_item_contactrequests.to_dict())
            _dict['contactrequests'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in conversations (list)
        _items = []
        if self.conversations:
            for _item_conversations in self.conversations:
                if _item_conversations:
                    _items.append(_item_conversations.to_dict())
            _dict['conversations'] = _items
        # set to None if cancreatecontact (nullable) is None
        # and model_fields_set contains the field
        if self.cancreatecontact is None and "cancreatecontact" in self.model_fields_set:
            _dict['cancreatecontact'] = None

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

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

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

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

        return _dict

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

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

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

        data = {
            "cancreatecontact": obj.get("cancreatecontact"),
            "canmessage": obj.get("canmessage"),
            "canmessageevenifblocked": obj.get("canmessageevenifblocked"),
            "contactrequests": [CoreMessageGetContactRequestsResponseInnerContactrequestsInner.from_dict(_item) for _item in obj["contactrequests"]] if obj.get("contactrequests") is not None else None,
            "conversations": [CoreMessageGetContactRequestsResponseInnerConversationsInner.from_dict(_item) for _item in obj["conversations"]] if obj.get("conversations") is not None else None,
            "fullname": obj.get("fullname"),
            "id": obj.get("id"),
            "isblocked": obj.get("isblocked"),
            "iscontact": obj.get("iscontact"),
            "isdeleted": obj.get("isdeleted"),
            "isonline": obj.get("isonline"),
            "profileimageurl": obj.get("profileimageurl"),
            "profileimageurlsmall": obj.get("profileimageurlsmall"),
            "profileurl": obj.get("profileurl"),
            "requirescontact": obj.get("requirescontact"),
            "showonlinestatus": obj.get("showonlinestatus")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


