from collections.abc import Mapping
from typing import (
    TYPE_CHECKING,
    Any,
    TypeVar,
    Union,
)

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.node_selector_term import NodeSelectorTerm


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


@_attrs_define
class NodeSelector:
    """
    Attributes:
        node_selector_terms (Union[Unset, list['NodeSelectorTerm']]):
    """

    node_selector_terms: Union[Unset, list["NodeSelectorTerm"]] = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        node_selector_terms: Union[Unset, list[dict[str, Any]]] = UNSET
        if not isinstance(self.node_selector_terms, Unset):
            node_selector_terms = []
            for node_selector_terms_item_data in self.node_selector_terms:
                node_selector_terms_item = node_selector_terms_item_data.to_dict()
                node_selector_terms.append(node_selector_terms_item)

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

        return field_dict

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

        d = dict(src_dict)
        node_selector_terms = []
        _node_selector_terms = d.pop("nodeSelectorTerms", UNSET)
        for node_selector_terms_item_data in _node_selector_terms or []:
            node_selector_terms_item = NodeSelectorTerm.from_dict(
                node_selector_terms_item_data
            )

            node_selector_terms.append(node_selector_terms_item)

        node_selector = cls(
            node_selector_terms=node_selector_terms,
        )

        node_selector.additional_properties = d
        return node_selector

    @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
