from __future__ import annotations

import datetime
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 dateutil.parser import isoparse

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.email_filters import EmailFilters
    from ..models.image_config import ImageConfig


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


@_attrs_define
class EmailSetting:
    """
    Attributes:
        provider (str | Unset):
        email (str | Unset):
        host (str | Unset):
        port (float | Unset):
        verified (bool | Unset):
        move_emails (bool | Unset):
        save_email (bool | Unset):
        attach_only (bool | Unset):
        formats (list[str] | Unset):
        filters (EmailFilters | Unset):
        images (ImageConfig | Unset):
        last_checked (datetime.datetime | Unset):
        last_sync (datetime.datetime | Unset):
        error (str | Unset):
        error_time (datetime.datetime | Unset):
        auth_error (datetime.datetime | Unset):
        next_retry (datetime.datetime | Unset):
        bulk (bool | Unset):
    """

    provider: str | Unset = UNSET
    email: str | Unset = UNSET
    host: str | Unset = UNSET
    port: float | Unset = UNSET
    verified: bool | Unset = UNSET
    move_emails: bool | Unset = UNSET
    save_email: bool | Unset = UNSET
    attach_only: bool | Unset = UNSET
    formats: list[str] | Unset = UNSET
    filters: EmailFilters | Unset = UNSET
    images: ImageConfig | Unset = UNSET
    last_checked: datetime.datetime | Unset = UNSET
    last_sync: datetime.datetime | Unset = UNSET
    error: str | Unset = UNSET
    error_time: datetime.datetime | Unset = UNSET
    auth_error: datetime.datetime | Unset = UNSET
    next_retry: datetime.datetime | Unset = UNSET
    bulk: bool | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        email = self.email

        host = self.host

        port = self.port

        verified = self.verified

        move_emails = self.move_emails

        save_email = self.save_email

        attach_only = self.attach_only

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

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

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

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

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

        error = self.error

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

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

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

        bulk = self.bulk

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if provider is not UNSET:
            field_dict["provider"] = provider
        if email is not UNSET:
            field_dict["email"] = email
        if host is not UNSET:
            field_dict["host"] = host
        if port is not UNSET:
            field_dict["port"] = port
        if verified is not UNSET:
            field_dict["verified"] = verified
        if move_emails is not UNSET:
            field_dict["moveEmails"] = move_emails
        if save_email is not UNSET:
            field_dict["saveEmail"] = save_email
        if attach_only is not UNSET:
            field_dict["attachOnly"] = attach_only
        if formats is not UNSET:
            field_dict["formats"] = formats
        if filters is not UNSET:
            field_dict["filters"] = filters
        if images is not UNSET:
            field_dict["images"] = images
        if last_checked is not UNSET:
            field_dict["lastChecked"] = last_checked
        if last_sync is not UNSET:
            field_dict["lastSync"] = last_sync
        if error is not UNSET:
            field_dict["error"] = error
        if error_time is not UNSET:
            field_dict["errorTime"] = error_time
        if auth_error is not UNSET:
            field_dict["authError"] = auth_error
        if next_retry is not UNSET:
            field_dict["nextRetry"] = next_retry
        if bulk is not UNSET:
            field_dict["bulk"] = bulk

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.email_filters import EmailFilters
        from ..models.image_config import ImageConfig

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

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

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

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

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

        move_emails = d.pop("moveEmails", UNSET)

        save_email = d.pop("saveEmail", UNSET)

        attach_only = d.pop("attachOnly", UNSET)

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

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

        _images = d.pop("images", UNSET)
        images: ImageConfig | Unset
        if isinstance(_images, Unset):
            images = UNSET
        else:
            images = ImageConfig.from_dict(_images)

        _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)

        _last_sync = d.pop("lastSync", UNSET)
        last_sync: datetime.datetime | Unset
        if isinstance(_last_sync, Unset):
            last_sync = UNSET
        else:
            last_sync = isoparse(_last_sync)

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

        _error_time = d.pop("errorTime", UNSET)
        error_time: datetime.datetime | Unset
        if isinstance(_error_time, Unset):
            error_time = UNSET
        else:
            error_time = isoparse(_error_time)

        _auth_error = d.pop("authError", UNSET)
        auth_error: datetime.datetime | Unset
        if isinstance(_auth_error, Unset):
            auth_error = UNSET
        else:
            auth_error = isoparse(_auth_error)

        _next_retry = d.pop("nextRetry", UNSET)
        next_retry: datetime.datetime | Unset
        if isinstance(_next_retry, Unset):
            next_retry = UNSET
        else:
            next_retry = isoparse(_next_retry)

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

        email_setting = cls(
            provider=provider,
            email=email,
            host=host,
            port=port,
            verified=verified,
            move_emails=move_emails,
            save_email=save_email,
            attach_only=attach_only,
            formats=formats,
            filters=filters,
            images=images,
            last_checked=last_checked,
            last_sync=last_sync,
            error=error,
            error_time=error_time,
            auth_error=auth_error,
            next_retry=next_retry,
            bulk=bulk,
        )

        email_setting.additional_properties = d
        return email_setting

    @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
