from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, cast

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.types_address import TypesAddress
    from ..models.types_client_role import TypesClientRole
    from ..models.types_field import TypesField
    from ..models.types_phone import TypesPhone
    from ..models.types_short_client import TypesShortClient


T = TypeVar("T", bound="TypesContact")


@_attrs_define
class TypesContact:
    """
    Attributes:
        field_id (str | Unset): Unique identifier
        address (TypesAddress | Unset):
        client (TypesShortClient | Unset):
        clients (list[TypesClientRole] | Unset): For searching
        company (str | Unset):
        confirmed (bool | Unset):
        email (list[str] | Unset):
        fields (list[TypesField] | Unset):
        name (str | Unset):
        notes (str | Unset):
        phone (list[TypesPhone] | Unset):
        preferred_name (str | Unset):
        suffix (str | Unset):
        tags (list[str] | Unset):
        team (str | Unset): What team does this contact belong to?
        title (str | Unset):
    """

    field_id: str | Unset = UNSET
    address: TypesAddress | Unset = UNSET
    client: TypesShortClient | Unset = UNSET
    clients: list[TypesClientRole] | Unset = UNSET
    company: str | Unset = UNSET
    confirmed: bool | Unset = UNSET
    email: list[str] | Unset = UNSET
    fields: list[TypesField] | Unset = UNSET
    name: str | Unset = UNSET
    notes: str | Unset = UNSET
    phone: list[TypesPhone] | Unset = UNSET
    preferred_name: str | Unset = UNSET
    suffix: str | Unset = UNSET
    tags: list[str] | Unset = UNSET
    team: str | Unset = UNSET
    title: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        field_id = self.field_id

        address: dict[str, Any] | Unset = UNSET
        if not isinstance(self.address, Unset):
            address = self.address.to_dict()

        client: dict[str, Any] | Unset = UNSET
        if not isinstance(self.client, Unset):
            client = self.client.to_dict()

        clients: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.clients, Unset):
            clients = []
            for clients_item_data in self.clients:
                clients_item = clients_item_data.to_dict()
                clients.append(clients_item)

        company = self.company

        confirmed = self.confirmed

        email: list[str] | Unset = UNSET
        if not isinstance(self.email, Unset):
            email = self.email

        fields: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.fields, Unset):
            fields = []
            for fields_item_data in self.fields:
                fields_item = fields_item_data.to_dict()
                fields.append(fields_item)

        name = self.name

        notes = self.notes

        phone: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.phone, Unset):
            phone = []
            for phone_item_data in self.phone:
                phone_item = phone_item_data.to_dict()
                phone.append(phone_item)

        preferred_name = self.preferred_name

        suffix = self.suffix

        tags: list[str] | Unset = UNSET
        if not isinstance(self.tags, Unset):
            tags = self.tags

        team = self.team

        title = self.title

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if field_id is not UNSET:
            field_dict["_id"] = field_id
        if address is not UNSET:
            field_dict["address"] = address
        if client is not UNSET:
            field_dict["client"] = client
        if clients is not UNSET:
            field_dict["clients"] = clients
        if company is not UNSET:
            field_dict["company"] = company
        if confirmed is not UNSET:
            field_dict["confirmed"] = confirmed
        if email is not UNSET:
            field_dict["email"] = email
        if fields is not UNSET:
            field_dict["fields"] = fields
        if name is not UNSET:
            field_dict["name"] = name
        if notes is not UNSET:
            field_dict["notes"] = notes
        if phone is not UNSET:
            field_dict["phone"] = phone
        if preferred_name is not UNSET:
            field_dict["preferred_name"] = preferred_name
        if suffix is not UNSET:
            field_dict["suffix"] = suffix
        if tags is not UNSET:
            field_dict["tags"] = tags
        if team is not UNSET:
            field_dict["team"] = team
        if title is not UNSET:
            field_dict["title"] = title

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_address import TypesAddress
        from ..models.types_client_role import TypesClientRole
        from ..models.types_field import TypesField
        from ..models.types_phone import TypesPhone
        from ..models.types_short_client import TypesShortClient

        d = dict(src_dict)
        field_id = d.pop("_id", UNSET)

        _address = d.pop("address", UNSET)
        address: TypesAddress | Unset
        if isinstance(_address, Unset):
            address = UNSET
        else:
            address = TypesAddress.from_dict(_address)

        _client = d.pop("client", UNSET)
        client: TypesShortClient | Unset
        if isinstance(_client, Unset):
            client = UNSET
        else:
            client = TypesShortClient.from_dict(_client)

        _clients = d.pop("clients", UNSET)
        clients: list[TypesClientRole] | Unset = UNSET
        if _clients is not UNSET:
            clients = []
            for clients_item_data in _clients:
                clients_item = TypesClientRole.from_dict(clients_item_data)

                clients.append(clients_item)

        company = d.pop("company", UNSET)

        confirmed = d.pop("confirmed", UNSET)

        email = cast(list[str], d.pop("email", UNSET))

        _fields = d.pop("fields", UNSET)
        fields: list[TypesField] | Unset = UNSET
        if _fields is not UNSET:
            fields = []
            for fields_item_data in _fields:
                fields_item = TypesField.from_dict(fields_item_data)

                fields.append(fields_item)

        name = d.pop("name", UNSET)

        notes = d.pop("notes", UNSET)

        _phone = d.pop("phone", UNSET)
        phone: list[TypesPhone] | Unset = UNSET
        if _phone is not UNSET:
            phone = []
            for phone_item_data in _phone:
                phone_item = TypesPhone.from_dict(phone_item_data)

                phone.append(phone_item)

        preferred_name = d.pop("preferred_name", UNSET)

        suffix = d.pop("suffix", UNSET)

        tags = cast(list[str], d.pop("tags", UNSET))

        team = d.pop("team", UNSET)

        title = d.pop("title", UNSET)

        types_contact = cls(
            field_id=field_id,
            address=address,
            client=client,
            clients=clients,
            company=company,
            confirmed=confirmed,
            email=email,
            fields=fields,
            name=name,
            notes=notes,
            phone=phone,
            preferred_name=preferred_name,
            suffix=suffix,
            tags=tags,
            team=team,
            title=title,
        )

        types_contact.additional_properties = d
        return types_contact

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
