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 ..models.search_web_config_search_type import SearchWebConfigSearchType
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.search_text_params import SearchTextParams


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


@_attrs_define
class SearchWebConfig:
    """
    Attributes:
        search_params (SearchTextParams):
        search_type (SearchWebConfigSearchType | Unset):  Default: SearchWebConfigSearchType.WEB.
    """

    search_params: SearchTextParams
    search_type: SearchWebConfigSearchType | Unset = SearchWebConfigSearchType.WEB
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        search_type: str | Unset = UNSET
        if not isinstance(self.search_type, Unset):
            search_type = self.search_type.value

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

        return field_dict

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

        d = dict(src_dict)
        search_params = SearchTextParams.from_dict(d.pop("search_params"))

        _search_type = d.pop("search_type", UNSET)
        search_type: SearchWebConfigSearchType | Unset
        if isinstance(_search_type, Unset):
            search_type = UNSET
        else:
            search_type = SearchWebConfigSearchType(_search_type)

        search_web_config = cls(
            search_params=search_params,
            search_type=search_type,
        )

        search_web_config.additional_properties = d
        return search_web_config

    @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
