from typing import TYPE_CHECKING, Any, TypeVar

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

if TYPE_CHECKING:
    from ..models.content_search_match import ContentSearchMatch


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


@_attrs_define
class ContentSearchResponse:
    """
    Attributes:
        matches (list['ContentSearchMatch']):
        query (str):  Example: searchText.
        total (int):  Example: 5.
    """

    matches: list["ContentSearchMatch"]
    query: str
    total: int
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        matches = []
        for matches_item_data in self.matches:
            if type(matches_item_data) is dict:
                matches_item = matches_item_data
            else:
                matches_item = matches_item_data.to_dict()
            matches.append(matches_item)

        query = self.query

        total = self.total

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "matches": matches,
                "query": query,
                "total": total,
            }
        )

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T | None:
        from ..models.content_search_match import ContentSearchMatch

        if not src_dict:
            return None
        d = src_dict.copy()
        matches = []
        _matches = d.pop("matches")
        for matches_item_data in _matches:
            matches_item = ContentSearchMatch.from_dict(matches_item_data)

            matches.append(matches_item)

        query = d.pop("query")

        total = d.pop("total")

        content_search_response = cls(
            matches=matches,
            query=query,
            total=total,
        )

        content_search_response.additional_properties = d
        return content_search_response

    @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
