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_section import TypesEmailSection


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


@_attrs_define
class TypesBrandedEmailTemplate:
    """
    Attributes:
        alignment (str | Unset):
        background_color (str | Unset): Not used now, but in case we want them in the future
        font_family (str | Unset):
        foreground_color (str | Unset):
        header_background (str | Unset):
        sections (list[TypesEmailSection] | Unset):
    """

    alignment: str | Unset = UNSET
    background_color: str | Unset = UNSET
    font_family: str | Unset = UNSET
    foreground_color: str | Unset = UNSET
    header_background: str | Unset = UNSET
    sections: list[TypesEmailSection] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        background_color = self.background_color

        font_family = self.font_family

        foreground_color = self.foreground_color

        header_background = self.header_background

        sections: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.sections, Unset):
            sections = []
            for sections_item_data in self.sections:
                sections_item = sections_item_data.to_dict()
                sections.append(sections_item)

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if alignment is not UNSET:
            field_dict["alignment"] = alignment
        if background_color is not UNSET:
            field_dict["background_color"] = background_color
        if font_family is not UNSET:
            field_dict["font_family"] = font_family
        if foreground_color is not UNSET:
            field_dict["foreground_color"] = foreground_color
        if header_background is not UNSET:
            field_dict["header_background"] = header_background
        if sections is not UNSET:
            field_dict["sections"] = sections

        return field_dict

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

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

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

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

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

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

        _sections = d.pop("sections", UNSET)
        sections: list[TypesEmailSection] | Unset = UNSET
        if _sections is not UNSET:
            sections = []
            for sections_item_data in _sections:
                sections_item = TypesEmailSection.from_dict(sections_item_data)

                sections.append(sections_item)

        types_branded_email_template = cls(
            alignment=alignment,
            background_color=background_color,
            font_family=font_family,
            foreground_color=foreground_color,
            header_background=header_background,
            sections=sections,
        )

        types_branded_email_template.additional_properties = d
        return types_branded_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
