# coding: utf-8

"""
    Conversations Inbox & Messages

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: v3
    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
from typing import Any, ClassVar, Dict, List, Optional
from hubspot.conversations.conversations.models.contact_address import ContactAddress
from hubspot.conversations.conversations.models.contact_email import ContactEmail
from hubspot.conversations.conversations.models.contact_name import ContactName
from hubspot.conversations.conversations.models.contact_org import ContactOrg
from hubspot.conversations.conversations.models.contact_phone import ContactPhone
from hubspot.conversations.conversations.models.contact_url import ContactUrl
from typing import Optional, Set
from typing_extensions import Self

class ContactProfile(BaseModel):
    """
    ContactProfile
    """ # noqa: E501
    emails: List[ContactEmail]
    addresses: List[ContactAddress]
    urls: List[ContactUrl]
    org: Optional[ContactOrg] = None
    name: Optional[ContactName] = None
    phones: List[ContactPhone]
    __properties: ClassVar[List[str]] = ["emails", "addresses", "urls", "org", "name", "phones"]

    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 ContactProfile 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 emails (list)
        _items = []
        if self.emails:
            for _item_emails in self.emails:
                if _item_emails:
                    _items.append(_item_emails.to_dict())
            _dict['emails'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in addresses (list)
        _items = []
        if self.addresses:
            for _item_addresses in self.addresses:
                if _item_addresses:
                    _items.append(_item_addresses.to_dict())
            _dict['addresses'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in urls (list)
        _items = []
        if self.urls:
            for _item_urls in self.urls:
                if _item_urls:
                    _items.append(_item_urls.to_dict())
            _dict['urls'] = _items
        # override the default output from pydantic by calling `to_dict()` of org
        if self.org:
            _dict['org'] = self.org.to_dict()
        # override the default output from pydantic by calling `to_dict()` of name
        if self.name:
            _dict['name'] = self.name.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in phones (list)
        _items = []
        if self.phones:
            for _item_phones in self.phones:
                if _item_phones:
                    _items.append(_item_phones.to_dict())
            _dict['phones'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "emails": [ContactEmail.from_dict(_item) for _item in obj["emails"]] if obj.get("emails") is not None else None,
            "addresses": [ContactAddress.from_dict(_item) for _item in obj["addresses"]] if obj.get("addresses") is not None else None,
            "urls": [ContactUrl.from_dict(_item) for _item in obj["urls"]] if obj.get("urls") is not None else None,
            "org": ContactOrg.from_dict(obj["org"]) if obj.get("org") is not None else None,
            "name": ContactName.from_dict(obj["name"]) if obj.get("name") is not None else None,
            "phones": [ContactPhone.from_dict(_item) for _item in obj["phones"]] if obj.get("phones") is not None else None
        })
        return _obj


