# coding: utf-8

"""
    Twenty Api

    Twenty is a customer relationship management (CRM) platform designed to help businesses manage their customer interactions and relationships effectively. The Twenty API provides programmatic access to the features and functionalities of the Twenty CRM platform, allowing developers to integrate and interact with the CRM data and operations.

    The version of the OpenAPI document: v0.1
    Contact: felix@twenty.com
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from uuid import UUID
from twentycrm_client.models.attachment_for_response import AttachmentForResponse
from twentycrm_client.models.attachment_for_response_created_by import AttachmentForResponseCreatedBy
from twentycrm_client.models.attachment_for_response_file_inner import AttachmentForResponseFileInner
from twentycrm_client.models.attachment_for_response_updated_by import AttachmentForResponseUpdatedBy
from twentycrm_client.models.person_emails import PersonEmails
from twentycrm_client.models.person_linkedin_link import PersonLinkedinLink
from twentycrm_client.models.person_name import PersonName
from twentycrm_client.models.person_phones import PersonPhones
from twentycrm_client.models.person_x_link import PersonXLink
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class PersonForResponse(BaseModel):
    """
    A person
    """ # noqa: E501
    id: Optional[UUID] = Field(default=None, description="Id")
    created_at: Optional[datetime] = Field(default=None, description="Creation date", alias="createdAt")
    updated_at: Optional[datetime] = Field(default=None, description="Last time the record was changed", alias="updatedAt")
    deleted_at: Optional[datetime] = Field(default=None, description="Date when the record was deleted", alias="deletedAt")
    name: Optional[PersonName] = None
    emails: Optional[PersonEmails] = None
    linkedin_link: Optional[PersonLinkedinLink] = Field(default=None, alias="linkedinLink")
    x_link: Optional[PersonXLink] = Field(default=None, alias="xLink")
    job_title: Optional[StrictStr] = Field(default=None, description="Contact's job title", alias="jobTitle")
    phones: Optional[PersonPhones] = None
    city: Optional[StrictStr] = Field(default=None, description="Contact's city")
    avatar_url: Optional[StrictStr] = Field(default=None, description="Contact's avatar", alias="avatarUrl")
    avatar_file: Optional[List[AttachmentForResponseFileInner]] = Field(default=None, description="Contact's avatar file", alias="avatarFile")
    position: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Person record Position")
    created_by: Optional[AttachmentForResponseCreatedBy] = Field(default=None, alias="createdBy")
    updated_by: Optional[AttachmentForResponseUpdatedBy] = Field(default=None, alias="updatedBy")
    company_id: Optional[UUID] = Field(default=None, alias="companyId")
    attachments: Optional[List[AttachmentForResponse]] = Field(default=None, description="Attachments linked to the contact.")
    calendar_event_participants: Optional[List[CalendarEventParticipantForResponse]] = Field(default=None, description="Calendar Event Participants", alias="calendarEventParticipants")
    company: Optional[CompanyForResponse] = None
    favorites: Optional[List[FavoriteForResponse]] = Field(default=None, description="Favorites linked to the contact")
    message_participants: Optional[List[MessageParticipantForResponse]] = Field(default=None, description="Message Participants", alias="messageParticipants")
    note_targets: Optional[List[NoteTargetForResponse]] = Field(default=None, description="Notes tied to the contact", alias="noteTargets")
    point_of_contact_for_opportunities: Optional[List[OpportunityForResponse]] = Field(default=None, description="List of opportunities for which that person is the point of contact", alias="pointOfContactForOpportunities")
    task_targets: Optional[List[TaskTargetForResponse]] = Field(default=None, description="Tasks tied to the contact", alias="taskTargets")
    timeline_activities: Optional[List[TimelineActivityForResponse]] = Field(default=None, description="Events linked to the person", alias="timelineActivities")
    __properties: ClassVar[List[str]] = ["id", "createdAt", "updatedAt", "deletedAt", "name", "emails", "linkedinLink", "xLink", "jobTitle", "phones", "city", "avatarUrl", "avatarFile", "position", "createdBy", "updatedBy", "companyId", "attachments", "calendarEventParticipants", "company", "favorites", "messageParticipants", "noteTargets", "pointOfContactForOpportunities", "taskTargets", "timelineActivities"]

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=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"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of PersonForResponse 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 name
        if self.name:
            _dict['name'] = self.name.to_dict()
        # override the default output from pydantic by calling `to_dict()` of emails
        if self.emails:
            _dict['emails'] = self.emails.to_dict()
        # override the default output from pydantic by calling `to_dict()` of linkedin_link
        if self.linkedin_link:
            _dict['linkedinLink'] = self.linkedin_link.to_dict()
        # override the default output from pydantic by calling `to_dict()` of x_link
        if self.x_link:
            _dict['xLink'] = self.x_link.to_dict()
        # override the default output from pydantic by calling `to_dict()` of phones
        if self.phones:
            _dict['phones'] = self.phones.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in avatar_file (list)
        _items = []
        if self.avatar_file:
            for _item_avatar_file in self.avatar_file:
                if _item_avatar_file:
                    _items.append(_item_avatar_file.to_dict())
            _dict['avatarFile'] = _items
        # override the default output from pydantic by calling `to_dict()` of created_by
        if self.created_by:
            _dict['createdBy'] = self.created_by.to_dict()
        # override the default output from pydantic by calling `to_dict()` of updated_by
        if self.updated_by:
            _dict['updatedBy'] = self.updated_by.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in attachments (list)
        _items = []
        if self.attachments:
            for _item_attachments in self.attachments:
                if _item_attachments:
                    _items.append(_item_attachments.to_dict())
            _dict['attachments'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in calendar_event_participants (list)
        _items = []
        if self.calendar_event_participants:
            for _item_calendar_event_participants in self.calendar_event_participants:
                if _item_calendar_event_participants:
                    _items.append(_item_calendar_event_participants.to_dict())
            _dict['calendarEventParticipants'] = _items
        # override the default output from pydantic by calling `to_dict()` of company
        if self.company:
            _dict['company'] = self.company.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in favorites (list)
        _items = []
        if self.favorites:
            for _item_favorites in self.favorites:
                if _item_favorites:
                    _items.append(_item_favorites.to_dict())
            _dict['favorites'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in message_participants (list)
        _items = []
        if self.message_participants:
            for _item_message_participants in self.message_participants:
                if _item_message_participants:
                    _items.append(_item_message_participants.to_dict())
            _dict['messageParticipants'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in note_targets (list)
        _items = []
        if self.note_targets:
            for _item_note_targets in self.note_targets:
                if _item_note_targets:
                    _items.append(_item_note_targets.to_dict())
            _dict['noteTargets'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in point_of_contact_for_opportunities (list)
        _items = []
        if self.point_of_contact_for_opportunities:
            for _item_point_of_contact_for_opportunities in self.point_of_contact_for_opportunities:
                if _item_point_of_contact_for_opportunities:
                    _items.append(_item_point_of_contact_for_opportunities.to_dict())
            _dict['pointOfContactForOpportunities'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in task_targets (list)
        _items = []
        if self.task_targets:
            for _item_task_targets in self.task_targets:
                if _item_task_targets:
                    _items.append(_item_task_targets.to_dict())
            _dict['taskTargets'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in timeline_activities (list)
        _items = []
        if self.timeline_activities:
            for _item_timeline_activities in self.timeline_activities:
                if _item_timeline_activities:
                    _items.append(_item_timeline_activities.to_dict())
            _dict['timelineActivities'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "createdAt": obj.get("createdAt"),
            "updatedAt": obj.get("updatedAt"),
            "deletedAt": obj.get("deletedAt"),
            "name": PersonName.from_dict(obj["name"]) if obj.get("name") is not None else None,
            "emails": PersonEmails.from_dict(obj["emails"]) if obj.get("emails") is not None else None,
            "linkedinLink": PersonLinkedinLink.from_dict(obj["linkedinLink"]) if obj.get("linkedinLink") is not None else None,
            "xLink": PersonXLink.from_dict(obj["xLink"]) if obj.get("xLink") is not None else None,
            "jobTitle": obj.get("jobTitle"),
            "phones": PersonPhones.from_dict(obj["phones"]) if obj.get("phones") is not None else None,
            "city": obj.get("city"),
            "avatarUrl": obj.get("avatarUrl"),
            "avatarFile": [AttachmentForResponseFileInner.from_dict(_item) for _item in obj["avatarFile"]] if obj.get("avatarFile") is not None else None,
            "position": obj.get("position"),
            "createdBy": AttachmentForResponseCreatedBy.from_dict(obj["createdBy"]) if obj.get("createdBy") is not None else None,
            "updatedBy": AttachmentForResponseUpdatedBy.from_dict(obj["updatedBy"]) if obj.get("updatedBy") is not None else None,
            "companyId": obj.get("companyId"),
            "attachments": [AttachmentForResponse.from_dict(_item) for _item in obj["attachments"]] if obj.get("attachments") is not None else None,
            "calendarEventParticipants": [CalendarEventParticipantForResponse.from_dict(_item) for _item in obj["calendarEventParticipants"]] if obj.get("calendarEventParticipants") is not None else None,
            "company": CompanyForResponse.from_dict(obj["company"]) if obj.get("company") is not None else None,
            "favorites": [FavoriteForResponse.from_dict(_item) for _item in obj["favorites"]] if obj.get("favorites") is not None else None,
            "messageParticipants": [MessageParticipantForResponse.from_dict(_item) for _item in obj["messageParticipants"]] if obj.get("messageParticipants") is not None else None,
            "noteTargets": [NoteTargetForResponse.from_dict(_item) for _item in obj["noteTargets"]] if obj.get("noteTargets") is not None else None,
            "pointOfContactForOpportunities": [OpportunityForResponse.from_dict(_item) for _item in obj["pointOfContactForOpportunities"]] if obj.get("pointOfContactForOpportunities") is not None else None,
            "taskTargets": [TaskTargetForResponse.from_dict(_item) for _item in obj["taskTargets"]] if obj.get("taskTargets") is not None else None,
            "timelineActivities": [TimelineActivityForResponse.from_dict(_item) for _item in obj["timelineActivities"]] if obj.get("timelineActivities") is not None else None
        })
        return _obj

from twentycrm_client.models.calendar_event_participant_for_response import CalendarEventParticipantForResponse
from twentycrm_client.models.company_for_response import CompanyForResponse
from twentycrm_client.models.favorite_for_response import FavoriteForResponse
from twentycrm_client.models.message_participant_for_response import MessageParticipantForResponse
from twentycrm_client.models.note_target_for_response import NoteTargetForResponse
from twentycrm_client.models.opportunity_for_response import OpportunityForResponse
from twentycrm_client.models.task_target_for_response import TaskTargetForResponse
from twentycrm_client.models.timeline_activity_for_response import TimelineActivityForResponse
# TODO: Rewrite to not use raise_errors
PersonForResponse.model_rebuild(raise_errors=False)

