from collections.abc import Mapping from typing import 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 ..types import UNSET, Unset T = TypeVar("T", bound="AdReport") @_attrs_define class AdReport: """ Attributes: visit_uuid (UUID): report_category (Union[None, ReportCategoryEnum, Unset]): report_reason (Union[None, Unset, str]): """ visit_uuid: UUID report_category: Union[None, ReportCategoryEnum, Unset] = UNSET report_reason: Union[None, Unset, str] = UNSET additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> dict[str, Any]: visit_uuid = str(self.visit_uuid) 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 report_reason: Union[None, Unset, str] if isinstance(self.report_reason, Unset): report_reason = UNSET else: report_reason = self.report_reason field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { "visit_uuid": visit_uuid, } ) if report_category is not UNSET: field_dict["report_category"] = report_category if report_reason is not UNSET: field_dict["report_reason"] = report_reason return field_dict @classmethod def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: d = dict(src_dict) visit_uuid = UUID(d.pop("visit_uuid")) 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)) 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)) ad_report = cls( visit_uuid=visit_uuid, report_category=report_category, report_reason=report_reason, ) ad_report.additional_properties = d return ad_report @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