from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar, cast

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

from ..models.match_rules_mode import MatchRulesMode
from ..types import UNSET, Unset

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


@_attrs_define
class MatchRules:
    """
    Attributes:
        mode (MatchRulesMode | Unset):
        source (list[str] | Unset):
        name (list[str] | Unset):
        phrases (list[str] | Unset):
    """

    mode: MatchRulesMode | Unset = UNSET
    source: list[str] | Unset = UNSET
    name: list[str] | Unset = UNSET
    phrases: list[str] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        mode: str | Unset = UNSET
        if not isinstance(self.mode, Unset):
            mode = self.mode.value

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

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

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

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if mode is not UNSET:
            field_dict["mode"] = mode
        if source is not UNSET:
            field_dict["source"] = source
        if name is not UNSET:
            field_dict["name"] = name
        if phrases is not UNSET:
            field_dict["phrases"] = phrases

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        _mode = d.pop("mode", UNSET)
        mode: MatchRulesMode | Unset
        if isinstance(_mode, Unset):
            mode = UNSET
        else:
            mode = MatchRulesMode(_mode)

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

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

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

        match_rules = cls(
            mode=mode,
            source=source,
            name=name,
            phrases=phrases,
        )

        match_rules.additional_properties = d
        return match_rules

    @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
