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_api_key import TypesAPIKey
    from ..models.types_email_config import TypesEmailConfig
    from ..models.types_filters import TypesFilters
    from ..models.types_preferences import TypesPreferences


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


@_attrs_define
class TypesMembership:
    """
    Attributes:
        about (str | Unset):
        accepted_on (str | Unset):
        api_keys (list[TypesAPIKey] | Unset):
        email (TypesEmailConfig | Unset):
        email_signature (str | Unset):
        filters (TypesFilters | Unset):
        invited_on (str | Unset):
        preferences (TypesPreferences | Unset):
        scopes (list[str] | Unset):
        starred_pages (list[str] | Unset):
        suspended (bool | Unset):
        team (str | Unset):
        title (str | Unset):
    """

    about: str | Unset = UNSET
    accepted_on: str | Unset = UNSET
    api_keys: list[TypesAPIKey] | Unset = UNSET
    email: TypesEmailConfig | Unset = UNSET
    email_signature: str | Unset = UNSET
    filters: TypesFilters | Unset = UNSET
    invited_on: str | Unset = UNSET
    preferences: TypesPreferences | Unset = UNSET
    scopes: list[str] | Unset = UNSET
    starred_pages: list[str] | Unset = UNSET
    suspended: bool | 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]:
        about = self.about

        accepted_on = self.accepted_on

        api_keys: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.api_keys, Unset):
            api_keys = []
            for api_keys_item_data in self.api_keys:
                api_keys_item = api_keys_item_data.to_dict()
                api_keys.append(api_keys_item)

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

        email_signature = self.email_signature

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

        invited_on = self.invited_on

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

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

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

        suspended = self.suspended

        team = self.team

        title = self.title

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if about is not UNSET:
            field_dict["about"] = about
        if accepted_on is not UNSET:
            field_dict["accepted_on"] = accepted_on
        if api_keys is not UNSET:
            field_dict["api_keys"] = api_keys
        if email is not UNSET:
            field_dict["email"] = email
        if email_signature is not UNSET:
            field_dict["email_signature"] = email_signature
        if filters is not UNSET:
            field_dict["filters"] = filters
        if invited_on is not UNSET:
            field_dict["invited_on"] = invited_on
        if preferences is not UNSET:
            field_dict["preferences"] = preferences
        if scopes is not UNSET:
            field_dict["scopes"] = scopes
        if starred_pages is not UNSET:
            field_dict["starred_pages"] = starred_pages
        if suspended is not UNSET:
            field_dict["suspended"] = suspended
        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_api_key import TypesAPIKey
        from ..models.types_email_config import TypesEmailConfig
        from ..models.types_filters import TypesFilters
        from ..models.types_preferences import TypesPreferences

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

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

        _api_keys = d.pop("api_keys", UNSET)
        api_keys: list[TypesAPIKey] | Unset = UNSET
        if _api_keys is not UNSET:
            api_keys = []
            for api_keys_item_data in _api_keys:
                api_keys_item = TypesAPIKey.from_dict(api_keys_item_data)

                api_keys.append(api_keys_item)

        _email = d.pop("email", UNSET)
        email: TypesEmailConfig | Unset
        if isinstance(_email, Unset):
            email = UNSET
        else:
            email = TypesEmailConfig.from_dict(_email)

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

        _filters = d.pop("filters", UNSET)
        filters: TypesFilters | Unset
        if isinstance(_filters, Unset):
            filters = UNSET
        else:
            filters = TypesFilters.from_dict(_filters)

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

        _preferences = d.pop("preferences", UNSET)
        preferences: TypesPreferences | Unset
        if isinstance(_preferences, Unset):
            preferences = UNSET
        else:
            preferences = TypesPreferences.from_dict(_preferences)

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

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

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

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

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

        types_membership = cls(
            about=about,
            accepted_on=accepted_on,
            api_keys=api_keys,
            email=email,
            email_signature=email_signature,
            filters=filters,
            invited_on=invited_on,
            preferences=preferences,
            scopes=scopes,
            starred_pages=starred_pages,
            suspended=suspended,
            team=team,
            title=title,
        )

        types_membership.additional_properties = d
        return types_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
