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.pkg_routes_clients_association_request import PkgRoutesClientsAssociationRequest
    from ..models.pkg_routes_clients_collaborate_permissions import PkgRoutesClientsCollaboratePermissions


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


@_attrs_define
class PkgRoutesClientsBulkContactRequest:
    """
    Attributes:
        association (PkgRoutesClientsAssociationRequest | Unset):
        client_ids (list[str] | Unset): Frontend sends string IDs
        contact_id (str | Unset): Frontend sends string ID - DEPRECATED: Use contactIds instead
        contact_ids (list[str] | Unset): Frontend sends string IDs - NEW: Support multiple contacts
        permissions (PkgRoutesClientsCollaboratePermissions | Unset):
        scopes (list[str] | Unset): For portal invitations
        to_contact_id (str | Unset): For replace operations
        type_ (str | Unset): "Remove", "Replace", "InvitePortal", "InviteCollaborate", "Associate"
    """

    association: PkgRoutesClientsAssociationRequest | Unset = UNSET
    client_ids: list[str] | Unset = UNSET
    contact_id: str | Unset = UNSET
    contact_ids: list[str] | Unset = UNSET
    permissions: PkgRoutesClientsCollaboratePermissions | Unset = UNSET
    scopes: list[str] | Unset = UNSET
    to_contact_id: str | Unset = UNSET
    type_: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        association: dict[str, Any] | Unset = UNSET
        if not isinstance(self.association, Unset):
            association = self.association.to_dict()

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

        contact_id = self.contact_id

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

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

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

        to_contact_id = self.to_contact_id

        type_ = self.type_

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if association is not UNSET:
            field_dict["association"] = association
        if client_ids is not UNSET:
            field_dict["clientIds"] = client_ids
        if contact_id is not UNSET:
            field_dict["contactId"] = contact_id
        if contact_ids is not UNSET:
            field_dict["contactIds"] = contact_ids
        if permissions is not UNSET:
            field_dict["permissions"] = permissions
        if scopes is not UNSET:
            field_dict["scopes"] = scopes
        if to_contact_id is not UNSET:
            field_dict["toContactId"] = to_contact_id
        if type_ is not UNSET:
            field_dict["type"] = type_

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.pkg_routes_clients_association_request import PkgRoutesClientsAssociationRequest
        from ..models.pkg_routes_clients_collaborate_permissions import PkgRoutesClientsCollaboratePermissions

        d = dict(src_dict)
        _association = d.pop("association", UNSET)
        association: PkgRoutesClientsAssociationRequest | Unset
        if isinstance(_association, Unset):
            association = UNSET
        else:
            association = PkgRoutesClientsAssociationRequest.from_dict(_association)

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

        contact_id = d.pop("contactId", UNSET)

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

        _permissions = d.pop("permissions", UNSET)
        permissions: PkgRoutesClientsCollaboratePermissions | Unset
        if isinstance(_permissions, Unset):
            permissions = UNSET
        else:
            permissions = PkgRoutesClientsCollaboratePermissions.from_dict(_permissions)

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

        to_contact_id = d.pop("toContactId", UNSET)

        type_ = d.pop("type", UNSET)

        pkg_routes_clients_bulk_contact_request = cls(
            association=association,
            client_ids=client_ids,
            contact_id=contact_id,
            contact_ids=contact_ids,
            permissions=permissions,
            scopes=scopes,
            to_contact_id=to_contact_id,
            type_=type_,
        )

        pkg_routes_clients_bulk_contact_request.additional_properties = d
        return pkg_routes_clients_bulk_contact_request

    @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
