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.notification import Notification


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


@_attrs_define
class Membership:
    """
    Attributes:
        team (str | Unset): MongoDB ObjectId
        is_admin (bool | Unset):
        is_suspended (bool | Unset):
        notifications (list[Notification] | Unset):
        notify_by_email (bool | Unset):
        send_daily_summary_by_email (bool | Unset):
        push_notifications (bool | Unset):
        keys (list[str] | Unset): API keys for this membership
    """

    team: str | Unset = UNSET
    is_admin: bool | Unset = UNSET
    is_suspended: bool | Unset = UNSET
    notifications: list[Notification] | Unset = UNSET
    notify_by_email: bool | Unset = UNSET
    send_daily_summary_by_email: bool | Unset = UNSET
    push_notifications: bool | Unset = UNSET
    keys: list[str] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        is_admin = self.is_admin

        is_suspended = self.is_suspended

        notifications: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.notifications, Unset):
            notifications = []
            for notifications_item_data in self.notifications:
                notifications_item = notifications_item_data.to_dict()
                notifications.append(notifications_item)

        notify_by_email = self.notify_by_email

        send_daily_summary_by_email = self.send_daily_summary_by_email

        push_notifications = self.push_notifications

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

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if team is not UNSET:
            field_dict["team"] = team
        if is_admin is not UNSET:
            field_dict["isAdmin"] = is_admin
        if is_suspended is not UNSET:
            field_dict["isSuspended"] = is_suspended
        if notifications is not UNSET:
            field_dict["notifications"] = notifications
        if notify_by_email is not UNSET:
            field_dict["notifyByEmail"] = notify_by_email
        if send_daily_summary_by_email is not UNSET:
            field_dict["sendDailySummaryByEmail"] = send_daily_summary_by_email
        if push_notifications is not UNSET:
            field_dict["pushNotifications"] = push_notifications
        if keys is not UNSET:
            field_dict["keys"] = keys

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.notification import Notification

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

        is_admin = d.pop("isAdmin", UNSET)

        is_suspended = d.pop("isSuspended", UNSET)

        _notifications = d.pop("notifications", UNSET)
        notifications: list[Notification] | Unset = UNSET
        if _notifications is not UNSET:
            notifications = []
            for notifications_item_data in _notifications:
                notifications_item = Notification.from_dict(notifications_item_data)

                notifications.append(notifications_item)

        notify_by_email = d.pop("notifyByEmail", UNSET)

        send_daily_summary_by_email = d.pop("sendDailySummaryByEmail", UNSET)

        push_notifications = d.pop("pushNotifications", UNSET)

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

        membership = cls(
            team=team,
            is_admin=is_admin,
            is_suspended=is_suspended,
            notifications=notifications,
            notify_by_email=notify_by_email,
            send_daily_summary_by_email=send_daily_summary_by_email,
            push_notifications=push_notifications,
            keys=keys,
        )

        membership.additional_properties = d
        return membership

    @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
