from __future__ import annotations

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

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_client_access import TypesClientAccess
    from ..models.types_membership import TypesMembership


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


@_attrs_define
class TypesUser:
    """
    Attributes:
        field_id (str | Unset):
        clients (list[TypesClientAccess] | Unset):
        community (str | Unset): Community role (eg. "Moderator")
        created_on (str | Unset):
        deleted_at (str | Unset):
        email (str | Unset):
        memberships (list[TypesMembership] | Unset):
        mfa_enabled (bool | Unset): Is MFA enabled?
        mfa_secret (str | Unset): The secret for MFA TOTP
        name (str | Unset):
        password (str | Unset):
        phone (str | Unset):
        signature (str | Unset):
        team (str | Unset): The team the user is logged in to
        validation_code (str | Unset): The validation code for the user
    """

    field_id: str | Unset = UNSET
    clients: list[TypesClientAccess] | Unset = UNSET
    community: str | Unset = UNSET
    created_on: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    email: str | Unset = UNSET
    memberships: list[TypesMembership] | Unset = UNSET
    mfa_enabled: bool | Unset = UNSET
    mfa_secret: str | Unset = UNSET
    name: str | Unset = UNSET
    password: str | Unset = UNSET
    phone: str | Unset = UNSET
    signature: str | Unset = UNSET
    team: str | Unset = UNSET
    validation_code: 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

        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)

        community = self.community

        created_on = self.created_on

        deleted_at = self.deleted_at

        email = self.email

        memberships: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.memberships, Unset):
            memberships = []
            for memberships_item_data in self.memberships:
                memberships_item = memberships_item_data.to_dict()
                memberships.append(memberships_item)

        mfa_enabled = self.mfa_enabled

        mfa_secret = self.mfa_secret

        name = self.name

        password = self.password

        phone = self.phone

        signature = self.signature

        team = self.team

        validation_code = self.validation_code

        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 clients is not UNSET:
            field_dict["clients"] = clients
        if community is not UNSET:
            field_dict["community"] = community
        if created_on is not UNSET:
            field_dict["created_on"] = created_on
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if email is not UNSET:
            field_dict["email"] = email
        if memberships is not UNSET:
            field_dict["memberships"] = memberships
        if mfa_enabled is not UNSET:
            field_dict["mfa_enabled"] = mfa_enabled
        if mfa_secret is not UNSET:
            field_dict["mfa_secret"] = mfa_secret
        if name is not UNSET:
            field_dict["name"] = name
        if password is not UNSET:
            field_dict["password"] = password
        if phone is not UNSET:
            field_dict["phone"] = phone
        if signature is not UNSET:
            field_dict["signature"] = signature
        if team is not UNSET:
            field_dict["team"] = team
        if validation_code is not UNSET:
            field_dict["validation_code"] = validation_code

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_client_access import TypesClientAccess
        from ..models.types_membership import TypesMembership

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

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

                clients.append(clients_item)

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

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

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

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

        _memberships = d.pop("memberships", UNSET)
        memberships: list[TypesMembership] | Unset = UNSET
        if _memberships is not UNSET:
            memberships = []
            for memberships_item_data in _memberships:
                memberships_item = TypesMembership.from_dict(memberships_item_data)

                memberships.append(memberships_item)

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

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

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

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

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

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

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

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

        types_user = cls(
            field_id=field_id,
            clients=clients,
            community=community,
            created_on=created_on,
            deleted_at=deleted_at,
            email=email,
            memberships=memberships,
            mfa_enabled=mfa_enabled,
            mfa_secret=mfa_secret,
            name=name,
            password=password,
            phone=phone,
            signature=signature,
            team=team,
            validation_code=validation_code,
        )

        types_user.additional_properties = d
        return types_user

    @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
