# 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, StrictBool, 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_updated_by import AttachmentForResponseUpdatedBy
from twentycrm_client.models.company_address import CompanyAddress
from twentycrm_client.models.company_annual_recurring_revenue import CompanyAnnualRecurringRevenue
from twentycrm_client.models.company_domain_name import CompanyDomainName
from twentycrm_client.models.company_linkedin_link import CompanyLinkedinLink
from twentycrm_client.models.company_x_link import CompanyXLink
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class CompanyForResponse(BaseModel):
    """
    A company
    """ # 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[StrictStr] = Field(default=None, description="The company name")
    domain_name: Optional[CompanyDomainName] = Field(default=None, alias="domainName")
    address: Optional[CompanyAddress] = None
    employees: Optional[StrictInt] = Field(default=None, description="Number of employees in the company")
    linkedin_link: Optional[CompanyLinkedinLink] = Field(default=None, alias="linkedinLink")
    x_link: Optional[CompanyXLink] = Field(default=None, alias="xLink")
    annual_recurring_revenue: Optional[CompanyAnnualRecurringRevenue] = Field(default=None, alias="annualRecurringRevenue")
    ideal_customer_profile: Optional[StrictBool] = Field(default=None, description="Ideal Customer Profile: Indicates whether the company is the most suitable and valuable customer for you", alias="idealCustomerProfile")
    position: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Company record position")
    created_by: Optional[AttachmentForResponseCreatedBy] = Field(default=None, alias="createdBy")
    updated_by: Optional[AttachmentForResponseUpdatedBy] = Field(default=None, alias="updatedBy")
    account_owner_id: Optional[UUID] = Field(default=None, alias="accountOwnerId")
    attachments: Optional[List[AttachmentForResponse]] = Field(default=None, description="Attachments linked to the company")
    people: Optional[List[PersonForResponse]] = Field(default=None, description="People linked to the company.")
    account_owner: Optional[WorkspaceMemberForResponse] = Field(default=None, alias="accountOwner")
    task_targets: Optional[List[TaskTargetForResponse]] = Field(default=None, description="Tasks tied to the company", alias="taskTargets")
    note_targets: Optional[List[NoteTargetForResponse]] = Field(default=None, description="Notes tied to the company", alias="noteTargets")
    opportunities: Optional[List[OpportunityForResponse]] = Field(default=None, description="Opportunities linked to the company.")
    favorites: Optional[List[FavoriteForResponse]] = Field(default=None, description="Favorites linked to the company")
    timeline_activities: Optional[List[TimelineActivityForResponse]] = Field(default=None, description="Timeline Activities linked to the company", alias="timelineActivities")
    __properties: ClassVar[List[str]] = ["id", "createdAt", "updatedAt", "deletedAt", "name", "domainName", "address", "employees", "linkedinLink", "xLink", "annualRecurringRevenue", "idealCustomerProfile", "position", "createdBy", "updatedBy", "accountOwnerId", "attachments", "people", "accountOwner", "taskTargets", "noteTargets", "opportunities", "favorites", "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 CompanyForResponse 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 domain_name
        if self.domain_name:
            _dict['domainName'] = self.domain_name.to_dict()
        # override the default output from pydantic by calling `to_dict()` of address
        if self.address:
            _dict['address'] = self.address.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 annual_recurring_revenue
        if self.annual_recurring_revenue:
            _dict['annualRecurringRevenue'] = self.annual_recurring_revenue.to_dict()
        # 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 people (list)
        _items = []
        if self.people:
            for _item_people in self.people:
                if _item_people:
                    _items.append(_item_people.to_dict())
            _dict['people'] = _items
        # override the default output from pydantic by calling `to_dict()` of account_owner
        if self.account_owner:
            _dict['accountOwner'] = self.account_owner.to_dict()
        # 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 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 opportunities (list)
        _items = []
        if self.opportunities:
            for _item_opportunities in self.opportunities:
                if _item_opportunities:
                    _items.append(_item_opportunities.to_dict())
            _dict['opportunities'] = _items
        # 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 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 CompanyForResponse 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": obj.get("name"),
            "domainName": CompanyDomainName.from_dict(obj["domainName"]) if obj.get("domainName") is not None else None,
            "address": CompanyAddress.from_dict(obj["address"]) if obj.get("address") is not None else None,
            "employees": obj.get("employees"),
            "linkedinLink": CompanyLinkedinLink.from_dict(obj["linkedinLink"]) if obj.get("linkedinLink") is not None else None,
            "xLink": CompanyXLink.from_dict(obj["xLink"]) if obj.get("xLink") is not None else None,
            "annualRecurringRevenue": CompanyAnnualRecurringRevenue.from_dict(obj["annualRecurringRevenue"]) if obj.get("annualRecurringRevenue") is not None else None,
            "idealCustomerProfile": obj.get("idealCustomerProfile"),
            "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,
            "accountOwnerId": obj.get("accountOwnerId"),
            "attachments": [AttachmentForResponse.from_dict(_item) for _item in obj["attachments"]] if obj.get("attachments") is not None else None,
            "people": [PersonForResponse.from_dict(_item) for _item in obj["people"]] if obj.get("people") is not None else None,
            "accountOwner": WorkspaceMemberForResponse.from_dict(obj["accountOwner"]) if obj.get("accountOwner") is not None else None,
            "taskTargets": [TaskTargetForResponse.from_dict(_item) for _item in obj["taskTargets"]] if obj.get("taskTargets") is not None else None,
            "noteTargets": [NoteTargetForResponse.from_dict(_item) for _item in obj["noteTargets"]] if obj.get("noteTargets") is not None else None,
            "opportunities": [OpportunityForResponse.from_dict(_item) for _item in obj["opportunities"]] if obj.get("opportunities") is not None else None,
            "favorites": [FavoriteForResponse.from_dict(_item) for _item in obj["favorites"]] if obj.get("favorites") 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.favorite_for_response import FavoriteForResponse
from twentycrm_client.models.note_target_for_response import NoteTargetForResponse
from twentycrm_client.models.opportunity_for_response import OpportunityForResponse
from twentycrm_client.models.person_for_response import PersonForResponse
from twentycrm_client.models.task_target_for_response import TaskTargetForResponse
from twentycrm_client.models.timeline_activity_for_response import TimelineActivityForResponse
from twentycrm_client.models.workspace_member_for_response import WorkspaceMemberForResponse
# TODO: Rewrite to not use raise_errors
CompanyForResponse.model_rebuild(raise_errors=False)

