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_search_highlight import TypesSearchHighlight
    from ..models.types_search_result_data import TypesSearchResultData


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


@_attrs_define
class TypesSearchResult:
    """
    Attributes:
        data (TypesSearchResultData | Unset):
        highlights (list[TypesSearchHighlight] | Unset):
        score (float | Unset):
        type_ (str | Unset):
    """

    data: TypesSearchResultData | Unset = UNSET
    highlights: list[TypesSearchHighlight] | Unset = UNSET
    score: float | Unset = UNSET
    type_: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        highlights: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.highlights, Unset):
            highlights = []
            for highlights_item_data in self.highlights:
                highlights_item = highlights_item_data.to_dict()
                highlights.append(highlights_item)

        score = self.score

        type_ = self.type_

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if data is not UNSET:
            field_dict["data"] = data
        if highlights is not UNSET:
            field_dict["highlights"] = highlights
        if score is not UNSET:
            field_dict["score"] = score
        if type_ is not UNSET:
            field_dict["type"] = type_

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.types_search_highlight import TypesSearchHighlight
        from ..models.types_search_result_data import TypesSearchResultData

        d = dict(src_dict)
        _data = d.pop("data", UNSET)
        data: TypesSearchResultData | Unset
        if isinstance(_data, Unset):
            data = UNSET
        else:
            data = TypesSearchResultData.from_dict(_data)

        _highlights = d.pop("highlights", UNSET)
        highlights: list[TypesSearchHighlight] | Unset = UNSET
        if _highlights is not UNSET:
            highlights = []
            for highlights_item_data in _highlights:
                highlights_item = TypesSearchHighlight.from_dict(highlights_item_data)

                highlights.append(highlights_item)

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

        type_ = d.pop("type", UNSET)

        types_search_result = cls(
            data=data,
            highlights=highlights,
            score=score,
            type_=type_,
        )

        types_search_result.additional_properties = d
        return types_search_result

    @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
