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 ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.types_clients_filter import TypesClientsFilter
    from ..models.types_plans_filter import TypesPlansFilter


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


@_attrs_define
class TypesEmailSchedule:
    """
    Attributes:
        allow_partial (bool | Unset): Partial send (rest will go to the Outbox)
        cc (list[str] | Unset): Variables (eg. "contacts:*")
        clients (list[str] | Unset):
        clients_filter (TypesClientsFilter | Unset):
        file (str | Unset): Who are we launching it for? (clients/plans)
        from_ (str | Unset): Variables to get From, To and Cc from client list or filtered clients
        plans (list[str] | Unset):
        plans_filter (TypesPlansFilter | Unset):
        timestamp (str | Unset): When are we launching it?
        to (list[str] | Unset): Variables (eg. "contacts:[role]")
    """

    allow_partial: bool | Unset = UNSET
    cc: list[str] | Unset = UNSET
    clients: list[str] | Unset = UNSET
    clients_filter: TypesClientsFilter | Unset = UNSET
    file: str | Unset = UNSET
    from_: str | Unset = UNSET
    plans: list[str] | Unset = UNSET
    plans_filter: TypesPlansFilter | Unset = UNSET
    timestamp: str | Unset = UNSET
    to: list[str] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

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

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

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

        file = self.file

        from_ = self.from_

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

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

        timestamp = self.timestamp

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

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if allow_partial is not UNSET:
            field_dict["allow_partial"] = allow_partial
        if cc is not UNSET:
            field_dict["cc"] = cc
        if clients is not UNSET:
            field_dict["clients"] = clients
        if clients_filter is not UNSET:
            field_dict["clients_filter"] = clients_filter
        if file is not UNSET:
            field_dict["file"] = file
        if from_ is not UNSET:
            field_dict["from"] = from_
        if plans is not UNSET:
            field_dict["plans"] = plans
        if plans_filter is not UNSET:
            field_dict["plans_filter"] = plans_filter
        if timestamp is not UNSET:
            field_dict["timestamp"] = timestamp
        if to is not UNSET:
            field_dict["to"] = to

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_clients_filter import TypesClientsFilter
        from ..models.types_plans_filter import TypesPlansFilter

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

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

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

        _clients_filter = d.pop("clients_filter", UNSET)
        clients_filter: TypesClientsFilter | Unset
        if isinstance(_clients_filter, Unset):
            clients_filter = UNSET
        else:
            clients_filter = TypesClientsFilter.from_dict(_clients_filter)

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

        from_ = d.pop("from", UNSET)

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

        _plans_filter = d.pop("plans_filter", UNSET)
        plans_filter: TypesPlansFilter | Unset
        if isinstance(_plans_filter, Unset):
            plans_filter = UNSET
        else:
            plans_filter = TypesPlansFilter.from_dict(_plans_filter)

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

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

        types_email_schedule = cls(
            allow_partial=allow_partial,
            cc=cc,
            clients=clients,
            clients_filter=clients_filter,
            file=file,
            from_=from_,
            plans=plans,
            plans_filter=plans_filter,
            timestamp=timestamp,
            to=to,
        )

        types_email_schedule.additional_properties = d
        return types_email_schedule

    @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
