from __future__ import annotations

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

if TYPE_CHECKING:
    from ..models.types_email_template import TypesEmailTemplate


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


@_attrs_define
class PkgRoutesLibraryEmailTemplatesListEmailTemplatesResponse:
    """
    Attributes:
        email_templates (list[TypesEmailTemplate] | Unset):
        total (int | Unset):
    """

    email_templates: list[TypesEmailTemplate] | Unset = UNSET
    total: int | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        email_templates: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.email_templates, Unset):
            email_templates = []
            for email_templates_item_data in self.email_templates:
                email_templates_item = email_templates_item_data.to_dict()
                email_templates.append(email_templates_item)

        total = self.total

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if email_templates is not UNSET:
            field_dict["email_templates"] = email_templates
        if total is not UNSET:
            field_dict["total"] = total

        return field_dict

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

        d = dict(src_dict)
        _email_templates = d.pop("email_templates", UNSET)
        email_templates: list[TypesEmailTemplate] | Unset = UNSET
        if _email_templates is not UNSET:
            email_templates = []
            for email_templates_item_data in _email_templates:
                email_templates_item = TypesEmailTemplate.from_dict(email_templates_item_data)

                email_templates.append(email_templates_item)

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

        pkg_routes_library_email_templates_list_email_templates_response = cls(
            email_templates=email_templates,
            total=total,
        )

        pkg_routes_library_email_templates_list_email_templates_response.additional_properties = d
        return pkg_routes_library_email_templates_list_email_templates_response

    @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
