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_history_results import TypesSearchHistoryResults


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


@_attrs_define
class TypesSearchHistory:
    """
    Attributes:
        field_id (str | Unset):
        context (str | Unset):
        query (str | Unset):
        results (TypesSearchHistoryResults | Unset): Number of results by type
        team (str | Unset):
        timestamp (str | Unset):
        user (str | Unset):
    """

    field_id: str | Unset = UNSET
    context: str | Unset = UNSET
    query: str | Unset = UNSET
    results: TypesSearchHistoryResults | Unset = UNSET
    team: str | Unset = UNSET
    timestamp: str | Unset = UNSET
    user: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        context = self.context

        query = self.query

        results: dict[str, Any] | Unset = UNSET
        if not isinstance(self.results, Unset):
            results = self.results.to_dict()

        team = self.team

        timestamp = self.timestamp

        user = self.user

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if field_id is not UNSET:
            field_dict["_id"] = field_id
        if context is not UNSET:
            field_dict["context"] = context
        if query is not UNSET:
            field_dict["query"] = query
        if results is not UNSET:
            field_dict["results"] = results
        if team is not UNSET:
            field_dict["team"] = team
        if timestamp is not UNSET:
            field_dict["timestamp"] = timestamp
        if user is not UNSET:
            field_dict["user"] = user

        return field_dict

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

        d = dict(src_dict)
        field_id = d.pop("_id", UNSET)

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

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

        _results = d.pop("results", UNSET)
        results: TypesSearchHistoryResults | Unset
        if isinstance(_results, Unset):
            results = UNSET
        else:
            results = TypesSearchHistoryResults.from_dict(_results)

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

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

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

        types_search_history = cls(
            field_id=field_id,
            context=context,
            query=query,
            results=results,
            team=team,
            timestamp=timestamp,
            user=user,
        )

        types_search_history.additional_properties = d
        return types_search_history

    @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
