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 ..models.security_two_factor_auth import SecurityTwoFactorAuth
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.sso_config import SSOConfig


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


@_attrs_define
class Security:
    """
    Attributes:
        two_factor_auth (SecurityTwoFactorAuth | Unset):
        whitelist (list[str] | Unset):
        sso (SSOConfig | Unset):
    """

    two_factor_auth: SecurityTwoFactorAuth | Unset = UNSET
    whitelist: list[str] | Unset = UNSET
    sso: SSOConfig | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

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

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

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if two_factor_auth is not UNSET:
            field_dict["twoFactorAuth"] = two_factor_auth
        if whitelist is not UNSET:
            field_dict["whitelist"] = whitelist
        if sso is not UNSET:
            field_dict["sso"] = sso

        return field_dict

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

        d = dict(src_dict)
        _two_factor_auth = d.pop("twoFactorAuth", UNSET)
        two_factor_auth: SecurityTwoFactorAuth | Unset
        if isinstance(_two_factor_auth, Unset):
            two_factor_auth = UNSET
        else:
            two_factor_auth = SecurityTwoFactorAuth(_two_factor_auth)

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

        _sso = d.pop("sso", UNSET)
        sso: SSOConfig | Unset
        if isinstance(_sso, Unset):
            sso = UNSET
        else:
            sso = SSOConfig.from_dict(_sso)

        security = cls(
            two_factor_auth=two_factor_auth,
            whitelist=whitelist,
            sso=sso,
        )

        security.additional_properties = d
        return security

    @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
