from collections.abc import Mapping from typing import TYPE_CHECKING, Any, TypeVar, Union, cast from uuid import UUID from attrs import define as _attrs_define from attrs import field as _attrs_field from .report_category_enum import ReportCategoryEnum from .visit_state_enum import VisitStateEnum from ..types import UNSET, Unset if TYPE_CHECKING: from .visit_location_type_0 import VisitLocationType0 T = TypeVar("T", bound="Visit") @_attrs_define class Visit: """ Attributes: uuid (UUID): ad (UUID): state (VisitStateEnum): * `0` - init * `1` - Start * `2` - done * `3` - Timeout * `4` - CACHED_BACK reward_amount (int): opportunity_until (str): display_time (str): location (Union['VisitLocationType0', None, Unset]): reaction (Union[None, Unset, str]): favorite (Union[None, Unset, bool]): bookmark (Union[None, Unset, bool]): report_reason (Union[None, Unset, str]): report_category (Union[None, ReportCategoryEnum, Unset]): """ uuid: UUID ad: UUID state: VisitStateEnum reward_amount: int opportunity_until: str display_time: str location: Union["VisitLocationType0", None, Unset] = UNSET reaction: Union[None, Unset, str] = UNSET favorite: Union[None, Unset, bool] = UNSET bookmark: Union[None, Unset, bool] = UNSET report_reason: Union[None, Unset, str] = UNSET report_category: Union[None, ReportCategoryEnum, Unset] = UNSET additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> dict[str, Any]: from .visit_location_type_0 import VisitLocationType0 uuid = str(self.uuid) ad = str(self.ad) state = self.state.value reward_amount = self.reward_amount opportunity_until = self.opportunity_until display_time = self.display_time location: Union[None, Unset, dict[str, Any]] if isinstance(self.location, Unset): location = UNSET elif isinstance(self.location, VisitLocationType0): location = self.location.to_dict() else: location = self.location reaction: Union[None, Unset, str] if isinstance(self.reaction, Unset): reaction = UNSET else: reaction = self.reaction favorite: Union[None, Unset, bool] if isinstance(self.favorite, Unset): favorite = UNSET else: favorite = self.favorite bookmark: Union[None, Unset, bool] if isinstance(self.bookmark, Unset): bookmark = UNSET else: bookmark = self.bookmark report_reason: Union[None, Unset, str] if isinstance(self.report_reason, Unset): report_reason = UNSET else: report_reason = self.report_reason report_category: Union[None, Unset, int] if isinstance(self.report_category, Unset): report_category = UNSET elif isinstance(self.report_category, ReportCategoryEnum): report_category = self.report_category.value else: report_category = self.report_category field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { "uuid": uuid, "ad": ad, "state": state, "reward_amount": reward_amount, "opportunity_until": opportunity_until, "display_time": display_time, } ) if location is not UNSET: field_dict["location"] = location if reaction is not UNSET: field_dict["reaction"] = reaction if favorite is not UNSET: field_dict["favorite"] = favorite if bookmark is not UNSET: field_dict["bookmark"] = bookmark if report_reason is not UNSET: field_dict["report_reason"] = report_reason if report_category is not UNSET: field_dict["report_category"] = report_category return field_dict @classmethod def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from .visit_location_type_0 import VisitLocationType0 d = dict(src_dict) uuid = UUID(d.pop("uuid")) ad = UUID(d.pop("ad")) state = VisitStateEnum(d.pop("state")) reward_amount = d.pop("reward_amount") opportunity_until = d.pop("opportunity_until") display_time = d.pop("display_time") def _parse_location(data: object) -> Union["VisitLocationType0", None, Unset]: if data is None: return data if isinstance(data, Unset): return data try: if not isinstance(data, dict): raise TypeError() location_type_0 = VisitLocationType0.from_dict(data) return location_type_0 except: # noqa: E722 pass return cast(Union["VisitLocationType0", None, Unset], data) location = _parse_location(d.pop("location", UNSET)) def _parse_reaction(data: object) -> Union[None, Unset, str]: if data is None: return data if isinstance(data, Unset): return data return cast(Union[None, Unset, str], data) reaction = _parse_reaction(d.pop("reaction", UNSET)) def _parse_favorite(data: object) -> Union[None, Unset, bool]: if data is None: return data if isinstance(data, Unset): return data return cast(Union[None, Unset, bool], data) favorite = _parse_favorite(d.pop("favorite", UNSET)) def _parse_bookmark(data: object) -> Union[None, Unset, bool]: if data is None: return data if isinstance(data, Unset): return data return cast(Union[None, Unset, bool], data) bookmark = _parse_bookmark(d.pop("bookmark", UNSET)) def _parse_report_reason(data: object) -> Union[None, Unset, str]: if data is None: return data if isinstance(data, Unset): return data return cast(Union[None, Unset, str], data) report_reason = _parse_report_reason(d.pop("report_reason", UNSET)) def _parse_report_category(data: object) -> Union[None, ReportCategoryEnum, Unset]: if data is None: return data if isinstance(data, Unset): return data try: if not isinstance(data, int): raise TypeError() report_category_type_0 = ReportCategoryEnum(data) return report_category_type_0 except: # noqa: E722 pass return cast(Union[None, ReportCategoryEnum, Unset], data) report_category = _parse_report_category(d.pop("report_category", UNSET)) visit = cls( uuid=uuid, ad=ad, state=state, reward_amount=reward_amount, opportunity_until=opportunity_until, display_time=display_time, location=location, reaction=reaction, favorite=favorite, bookmark=bookmark, report_reason=report_reason, report_category=report_category, ) visit.additional_properties = d return visit @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