from __future__ import annotations

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

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

from ..types import UNSET, Unset

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


@_attrs_define
class TeammateResponse:
    """Attributes:
    id (str):
    fid (str):
    project_ids (list[str]):
    user_name (None | str | Unset):
    email (None | str | Unset):
    organization_role (None | str | Unset):
    deactivated_at (None | str | Unset):
    """

    id: str
    fid: str
    project_ids: list[str]
    user_name: None | str | Unset = UNSET
    email: None | str | Unset = UNSET
    organization_role: None | str | Unset = UNSET
    deactivated_at: None | str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        fid = self.fid

        project_ids = self.project_ids

        user_name: None | str | Unset
        if isinstance(self.user_name, Unset):
            user_name = UNSET
        else:
            user_name = self.user_name

        email: None | str | Unset
        if isinstance(self.email, Unset):
            email = UNSET
        else:
            email = self.email

        organization_role: None | str | Unset
        if isinstance(self.organization_role, Unset):
            organization_role = UNSET
        else:
            organization_role = self.organization_role

        deactivated_at: None | str | Unset
        if isinstance(self.deactivated_at, Unset):
            deactivated_at = UNSET
        else:
            deactivated_at = self.deactivated_at

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "id": id,
                "fid": fid,
                "project_ids": project_ids,
            }
        )
        if user_name is not UNSET:
            field_dict["user_name"] = user_name
        if email is not UNSET:
            field_dict["email"] = email
        if organization_role is not UNSET:
            field_dict["organization_role"] = organization_role
        if deactivated_at is not UNSET:
            field_dict["deactivated_at"] = deactivated_at

        return field_dict

    @classmethod
    def from_dict(cls, src_dict: Mapping[str, Any]) -> Self:
        d = dict(src_dict)
        id = d.pop("id")

        fid = d.pop("fid")

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

        def _parse_user_name(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        user_name = _parse_user_name(d.pop("user_name", UNSET))

        def _parse_email(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

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

        def _parse_organization_role(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        organization_role = _parse_organization_role(d.pop("organization_role", UNSET))

        def _parse_deactivated_at(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        deactivated_at = _parse_deactivated_at(d.pop("deactivated_at", UNSET))

        teammate_response = cls(
            id=id,
            fid=fid,
            project_ids=project_ids,
            user_name=user_name,
            email=email,
            organization_role=organization_role,
            deactivated_at=deactivated_at,
        )

        teammate_response.additional_properties = d
        return teammate_response

    @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
