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_activity import TypesActivity
    from ..models.types_branded_email_template import TypesBrandedEmailTemplate
    from ..models.types_email_schedule import TypesEmailSchedule


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


@_attrs_define
class TypesEmailTemplate:
    """
    Attributes:
        field_id (str | Unset):
        activity (list[TypesActivity] | Unset): For returning
        append_signature (bool | Unset):
        attachments (list[str] | Unset):
        body (str | Unset):
        branded (TypesBrandedEmailTemplate | Unset):
        created_at (str | Unset):
        deleted_at (str | Unset):
        locked (bool | Unset):
        name (str | Unset):
        schedule (list[TypesEmailSchedule] | Unset):
        secure (bool | Unset):
        subject (str | Unset):
        tags (list[str] | Unset):
        team (str | Unset):
    """

    field_id: str | Unset = UNSET
    activity: list[TypesActivity] | Unset = UNSET
    append_signature: bool | Unset = UNSET
    attachments: list[str] | Unset = UNSET
    body: str | Unset = UNSET
    branded: TypesBrandedEmailTemplate | Unset = UNSET
    created_at: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    locked: bool | Unset = UNSET
    name: str | Unset = UNSET
    schedule: list[TypesEmailSchedule] | Unset = UNSET
    secure: bool | Unset = UNSET
    subject: str | Unset = UNSET
    tags: list[str] | Unset = UNSET
    team: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        activity: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.activity, Unset):
            activity = []
            for activity_item_data in self.activity:
                activity_item = activity_item_data.to_dict()
                activity.append(activity_item)

        append_signature = self.append_signature

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

        body = self.body

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

        created_at = self.created_at

        deleted_at = self.deleted_at

        locked = self.locked

        name = self.name

        schedule: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.schedule, Unset):
            schedule = []
            for schedule_item_data in self.schedule:
                schedule_item = schedule_item_data.to_dict()
                schedule.append(schedule_item)

        secure = self.secure

        subject = self.subject

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

        team = self.team

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if field_id is not UNSET:
            field_dict["_id"] = field_id
        if activity is not UNSET:
            field_dict["activity"] = activity
        if append_signature is not UNSET:
            field_dict["append_signature"] = append_signature
        if attachments is not UNSET:
            field_dict["attachments"] = attachments
        if body is not UNSET:
            field_dict["body"] = body
        if branded is not UNSET:
            field_dict["branded"] = branded
        if created_at is not UNSET:
            field_dict["created_at"] = created_at
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if locked is not UNSET:
            field_dict["locked"] = locked
        if name is not UNSET:
            field_dict["name"] = name
        if schedule is not UNSET:
            field_dict["schedule"] = schedule
        if secure is not UNSET:
            field_dict["secure"] = secure
        if subject is not UNSET:
            field_dict["subject"] = subject
        if tags is not UNSET:
            field_dict["tags"] = tags
        if team is not UNSET:
            field_dict["team"] = team

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_activity import TypesActivity
        from ..models.types_branded_email_template import TypesBrandedEmailTemplate
        from ..models.types_email_schedule import TypesEmailSchedule

        d = dict(src_dict)
        field_id = d.pop("_id", UNSET)

        _activity = d.pop("activity", UNSET)
        activity: list[TypesActivity] | Unset = UNSET
        if _activity is not UNSET:
            activity = []
            for activity_item_data in _activity:
                activity_item = TypesActivity.from_dict(activity_item_data)

                activity.append(activity_item)

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

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

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

        _branded = d.pop("branded", UNSET)
        branded: TypesBrandedEmailTemplate | Unset
        if isinstance(_branded, Unset):
            branded = UNSET
        else:
            branded = TypesBrandedEmailTemplate.from_dict(_branded)

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

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

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

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

        _schedule = d.pop("schedule", UNSET)
        schedule: list[TypesEmailSchedule] | Unset = UNSET
        if _schedule is not UNSET:
            schedule = []
            for schedule_item_data in _schedule:
                schedule_item = TypesEmailSchedule.from_dict(schedule_item_data)

                schedule.append(schedule_item)

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

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

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

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

        types_email_template = cls(
            field_id=field_id,
            activity=activity,
            append_signature=append_signature,
            attachments=attachments,
            body=body,
            branded=branded,
            created_at=created_at,
            deleted_at=deleted_at,
            locked=locked,
            name=name,
            schedule=schedule,
            secure=secure,
            subject=subject,
            tags=tags,
            team=team,
        )

        types_email_template.additional_properties = d
        return types_email_template

    @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
