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_custom_field import TypesCustomField


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


@_attrs_define
class TypesAutomation:
    """
    Attributes:
        field_id (str | Unset):
        config (list[TypesCustomField] | Unset):
        description (str | Unset):
        enabled (bool | Unset):
        icon (str | Unset):
        name (str | Unset):
        public (bool | Unset):
        url (str | Unset):
    """

    field_id: str | Unset = UNSET
    config: list[TypesCustomField] | Unset = UNSET
    description: str | Unset = UNSET
    enabled: bool | Unset = UNSET
    icon: str | Unset = UNSET
    name: str | Unset = UNSET
    public: bool | Unset = UNSET
    url: 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

        config: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.config, Unset):
            config = []
            for config_item_data in self.config:
                config_item = config_item_data.to_dict()
                config.append(config_item)

        description = self.description

        enabled = self.enabled

        icon = self.icon

        name = self.name

        public = self.public

        url = self.url

        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 config is not UNSET:
            field_dict["config"] = config
        if description is not UNSET:
            field_dict["description"] = description
        if enabled is not UNSET:
            field_dict["enabled"] = enabled
        if icon is not UNSET:
            field_dict["icon"] = icon
        if name is not UNSET:
            field_dict["name"] = name
        if public is not UNSET:
            field_dict["public"] = public
        if url is not UNSET:
            field_dict["url"] = url

        return field_dict

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

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

        _config = d.pop("config", UNSET)
        config: list[TypesCustomField] | Unset = UNSET
        if _config is not UNSET:
            config = []
            for config_item_data in _config:
                config_item = TypesCustomField.from_dict(config_item_data)

                config.append(config_item)

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

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

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

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

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

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

        types_automation = cls(
            field_id=field_id,
            config=config,
            description=description,
            enabled=enabled,
            icon=icon,
            name=name,
            public=public,
            url=url,
        )

        types_automation.additional_properties = d
        return types_automation

    @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
