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_text import TypesSearchHighlightText


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


@_attrs_define
class TypesSearchHighlight:
    """
    Attributes:
        path (str | Unset):
        score (float | Unset): The score of the highlight
        texts (list[TypesSearchHighlightText] | Unset): The text to highlight
    """

    path: str | Unset = UNSET
    score: float | Unset = UNSET
    texts: list[TypesSearchHighlightText] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        score = self.score

        texts: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.texts, Unset):
            texts = []
            for texts_item_data in self.texts:
                texts_item = texts_item_data.to_dict()
                texts.append(texts_item)

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

        return field_dict

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

        d = dict(src_dict)
        path = d.pop("path", UNSET)

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

        _texts = d.pop("texts", UNSET)
        texts: list[TypesSearchHighlightText] | Unset = UNSET
        if _texts is not UNSET:
            texts = []
            for texts_item_data in _texts:
                texts_item = TypesSearchHighlightText.from_dict(texts_item_data)

                texts.append(texts_item)

        types_search_highlight = cls(
            path=path,
            score=score,
            texts=texts,
        )

        types_search_highlight.additional_properties = d
        return types_search_highlight

    @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
