from __future__ import annotations

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

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

from ..models.mail_smtp_auth_type import MailSMTPAuthType
from ..types import UNSET, Unset

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


@_attrs_define
class LegacytypesSMTPConfiguration:
    """
    Attributes:
        auth_method (MailSMTPAuthType | Unset):
        enabled (bool | Unset):
        host (str | Unset):
        password (str | Unset):
        port (int | Unset):
        require_tls (bool | Unset):
        username (str | Unset):
    """

    auth_method: MailSMTPAuthType | Unset = UNSET
    enabled: bool | Unset = UNSET
    host: str | Unset = UNSET
    password: str | Unset = UNSET
    port: int | Unset = UNSET
    require_tls: bool | Unset = UNSET
    username: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        enabled = self.enabled

        host = self.host

        password = self.password

        port = self.port

        require_tls = self.require_tls

        username = self.username

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if auth_method is not UNSET:
            field_dict["auth_method"] = auth_method
        if enabled is not UNSET:
            field_dict["enabled"] = enabled
        if host is not UNSET:
            field_dict["host"] = host
        if password is not UNSET:
            field_dict["password"] = password
        if port is not UNSET:
            field_dict["port"] = port
        if require_tls is not UNSET:
            field_dict["require_tls"] = require_tls
        if username is not UNSET:
            field_dict["username"] = username

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        _auth_method = d.pop("auth_method", UNSET)
        auth_method: MailSMTPAuthType | Unset
        if isinstance(_auth_method, Unset):
            auth_method = UNSET
        else:
            auth_method = MailSMTPAuthType(_auth_method)

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

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

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

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

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

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

        legacytypes_smtp_configuration = cls(
            auth_method=auth_method,
            enabled=enabled,
            host=host,
            password=password,
            port=port,
            require_tls=require_tls,
            username=username,
        )

        legacytypes_smtp_configuration.additional_properties = d
        return legacytypes_smtp_configuration

    @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
