# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from uuid import UUID
from twentycrm_client.models.workspace_member_name import WorkspaceMemberName
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class WorkspaceMemberForResponse(BaseModel):
    """
    A workspace member
    """ # 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")
    position: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Workspace member position")
    name: Optional[WorkspaceMemberName] = None
    color_scheme: Optional[StrictStr] = Field(default=None, description="Preferred color scheme", alias="colorScheme")
    locale: Optional[StrictStr] = Field(default=None, description="Preferred language")
    avatar_url: Optional[StrictStr] = Field(default=None, description="Workspace member avatar", alias="avatarUrl")
    user_email: Optional[StrictStr] = Field(default=None, description="Related user email address", alias="userEmail")
    calendar_start_day: Optional[StrictInt] = Field(default=None, description="User's preferred start day of the week", alias="calendarStartDay")
    user_id: Optional[UUID] = Field(default=None, description="Associated User Id", alias="userId")
    time_zone: Optional[StrictStr] = Field(default=None, description="User time zone", alias="timeZone")
    date_format: Optional[StrictStr] = Field(default=None, description="User's preferred date format", alias="dateFormat")
    time_format: Optional[StrictStr] = Field(default=None, description="User's preferred time format", alias="timeFormat")
    number_format: Optional[StrictStr] = Field(default=None, description="User's preferred number format", alias="numberFormat")
    blocklist: Optional[List[BlocklistForResponse]] = Field(default=None, description="Blocklisted handles")
    calendar_event_participants: Optional[List[CalendarEventParticipantForResponse]] = Field(default=None, description="Calendar Event Participants", alias="calendarEventParticipants")
    account_owner_for_companies: Optional[List[CompanyForResponse]] = Field(default=None, description="Account owner for companies", alias="accountOwnerForCompanies")
    connected_accounts: Optional[List[ConnectedAccountForResponse]] = Field(default=None, description="Connected accounts", alias="connectedAccounts")
    favorites: Optional[List[FavoriteForResponse]] = Field(default=None, description="Favorites linked to the workspace member")
    message_participants: Optional[List[MessageParticipantForResponse]] = Field(default=None, description="Message Participants", alias="messageParticipants")
    owned_opportunities: Optional[List[OpportunityForResponse]] = Field(default=None, description="Opportunities owned by the workspace member", alias="ownedOpportunities")
    assigned_tasks: Optional[List[TaskForResponse]] = Field(default=None, description="Tasks assigned to the workspace member", alias="assignedTasks")
    timeline_activities: Optional[List[TimelineActivityForResponse]] = Field(default=None, description="Events linked to the workspace member", alias="timelineActivities")
    __properties: ClassVar[List[str]] = ["id", "createdAt", "updatedAt", "deletedAt", "position", "name", "colorScheme", "locale", "avatarUrl", "userEmail", "calendarStartDay", "userId", "timeZone", "dateFormat", "timeFormat", "numberFormat", "blocklist", "calendarEventParticipants", "accountOwnerForCompanies", "connectedAccounts", "favorites", "messageParticipants", "ownedOpportunities", "assignedTasks", "timelineActivities"]

    @field_validator('date_format')
    def date_format_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['SYSTEM', 'MONTH_FIRST', 'DAY_FIRST', 'YEAR_FIRST']):
            raise ValueError("must be one of enum values ('SYSTEM', 'MONTH_FIRST', 'DAY_FIRST', 'YEAR_FIRST')")
        return value

    @field_validator('time_format')
    def time_format_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['SYSTEM', 'HOUR_24', 'HOUR_12']):
            raise ValueError("must be one of enum values ('SYSTEM', 'HOUR_24', 'HOUR_12')")
        return value

    @field_validator('number_format')
    def number_format_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['SYSTEM', 'COMMAS_AND_DOT', 'SPACES_AND_COMMA', 'DOTS_AND_COMMA', 'APOSTROPHE_AND_DOT']):
            raise ValueError("must be one of enum values ('SYSTEM', 'COMMAS_AND_DOT', 'SPACES_AND_COMMA', 'DOTS_AND_COMMA', 'APOSTROPHE_AND_DOT')")
        return value

    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 WorkspaceMemberForResponse 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 each item in blocklist (list)
        _items = []
        if self.blocklist:
            for _item_blocklist in self.blocklist:
                if _item_blocklist:
                    _items.append(_item_blocklist.to_dict())
            _dict['blocklist'] = _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 each item in account_owner_for_companies (list)
        _items = []
        if self.account_owner_for_companies:
            for _item_account_owner_for_companies in self.account_owner_for_companies:
                if _item_account_owner_for_companies:
                    _items.append(_item_account_owner_for_companies.to_dict())
            _dict['accountOwnerForCompanies'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in connected_accounts (list)
        _items = []
        if self.connected_accounts:
            for _item_connected_accounts in self.connected_accounts:
                if _item_connected_accounts:
                    _items.append(_item_connected_accounts.to_dict())
            _dict['connectedAccounts'] = _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 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 owned_opportunities (list)
        _items = []
        if self.owned_opportunities:
            for _item_owned_opportunities in self.owned_opportunities:
                if _item_owned_opportunities:
                    _items.append(_item_owned_opportunities.to_dict())
            _dict['ownedOpportunities'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in assigned_tasks (list)
        _items = []
        if self.assigned_tasks:
            for _item_assigned_tasks in self.assigned_tasks:
                if _item_assigned_tasks:
                    _items.append(_item_assigned_tasks.to_dict())
            _dict['assignedTasks'] = _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 WorkspaceMemberForResponse 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"),
            "position": obj.get("position"),
            "name": WorkspaceMemberName.from_dict(obj["name"]) if obj.get("name") is not None else None,
            "colorScheme": obj.get("colorScheme"),
            "locale": obj.get("locale"),
            "avatarUrl": obj.get("avatarUrl"),
            "userEmail": obj.get("userEmail"),
            "calendarStartDay": obj.get("calendarStartDay"),
            "userId": obj.get("userId"),
            "timeZone": obj.get("timeZone"),
            "dateFormat": obj.get("dateFormat"),
            "timeFormat": obj.get("timeFormat"),
            "numberFormat": obj.get("numberFormat"),
            "blocklist": [BlocklistForResponse.from_dict(_item) for _item in obj["blocklist"]] if obj.get("blocklist") is not None else None,
            "calendarEventParticipants": [CalendarEventParticipantForResponse.from_dict(_item) for _item in obj["calendarEventParticipants"]] if obj.get("calendarEventParticipants") is not None else None,
            "accountOwnerForCompanies": [CompanyForResponse.from_dict(_item) for _item in obj["accountOwnerForCompanies"]] if obj.get("accountOwnerForCompanies") is not None else None,
            "connectedAccounts": [ConnectedAccountForResponse.from_dict(_item) for _item in obj["connectedAccounts"]] if obj.get("connectedAccounts") 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,
            "ownedOpportunities": [OpportunityForResponse.from_dict(_item) for _item in obj["ownedOpportunities"]] if obj.get("ownedOpportunities") is not None else None,
            "assignedTasks": [TaskForResponse.from_dict(_item) for _item in obj["assignedTasks"]] if obj.get("assignedTasks") 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.blocklist_for_response import BlocklistForResponse
from twentycrm_client.models.calendar_event_participant_for_response import CalendarEventParticipantForResponse
from twentycrm_client.models.company_for_response import CompanyForResponse
from twentycrm_client.models.connected_account_for_response import ConnectedAccountForResponse
from twentycrm_client.models.favorite_for_response import FavoriteForResponse
from twentycrm_client.models.message_participant_for_response import MessageParticipantForResponse
from twentycrm_client.models.opportunity_for_response import OpportunityForResponse
from twentycrm_client.models.task_for_response import TaskForResponse
from twentycrm_client.models.timeline_activity_for_response import TimelineActivityForResponse
# TODO: Rewrite to not use raise_errors
WorkspaceMemberForResponse.model_rebuild(raise_errors=False)

