from __future__ import annotations

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

from attrs import define as _attrs_define
from attrs import field as _attrs_field
from dateutil.parser import isoparse

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.email_setting import EmailSetting


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


@_attrs_define
class EmailConfig:
    """
    Attributes:
        enable_inbound (bool | Unset):
        enable_outbound (bool | Unset):
        settings (list[EmailSetting] | Unset):
        last_checked (datetime.datetime | Unset):
    """

    enable_inbound: bool | Unset = UNSET
    enable_outbound: bool | Unset = UNSET
    settings: list[EmailSetting] | Unset = UNSET
    last_checked: datetime.datetime | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        enable_outbound = self.enable_outbound

        settings: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.settings, Unset):
            settings = []
            for settings_item_data in self.settings:
                settings_item = settings_item_data.to_dict()
                settings.append(settings_item)

        last_checked: str | Unset = UNSET
        if not isinstance(self.last_checked, Unset):
            last_checked = self.last_checked.isoformat()

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if enable_inbound is not UNSET:
            field_dict["enableInbound"] = enable_inbound
        if enable_outbound is not UNSET:
            field_dict["enableOutbound"] = enable_outbound
        if settings is not UNSET:
            field_dict["settings"] = settings
        if last_checked is not UNSET:
            field_dict["lastChecked"] = last_checked

        return field_dict

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

        d = dict(src_dict)
        enable_inbound = d.pop("enableInbound", UNSET)

        enable_outbound = d.pop("enableOutbound", UNSET)

        _settings = d.pop("settings", UNSET)
        settings: list[EmailSetting] | Unset = UNSET
        if _settings is not UNSET:
            settings = []
            for settings_item_data in _settings:
                settings_item = EmailSetting.from_dict(settings_item_data)

                settings.append(settings_item)

        _last_checked = d.pop("lastChecked", UNSET)
        last_checked: datetime.datetime | Unset
        if isinstance(_last_checked, Unset):
            last_checked = UNSET
        else:
            last_checked = isoparse(_last_checked)

        email_config = cls(
            enable_inbound=enable_inbound,
            enable_outbound=enable_outbound,
            settings=settings,
            last_checked=last_checked,
        )

        email_config.additional_properties = d
        return email_config

    @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
