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 .type_0d9_enum import Type0D9Enum from ..types import UNSET, Unset if TYPE_CHECKING: from .ad_content import AdContent from .ad_public_location_type_0 import AdPublicLocationType0 from .refined_ad_banner import RefinedAdBanner from .refined_ad_content import RefinedAdContent T = TypeVar("T", bound="AdPublic") @_attrs_define class AdPublic: """ Attributes: uuid (UUID): title (Union[None, str]): type_ (Type0D9Enum): * `1` - BILLBOARD * `2` - CAPTURED_BILLBOARD * `99` - PROMOTION * `100` - CONSTANT reward_amount (int): content (str): contents (list['AdContent']): refined_contents (list['RefinedAdContent']): description (Union[None, str]): location (Union['AdPublicLocationType0', None]): location_is_approximate (bool): banner (Union[None, str]): address (Union[None, str]): url (Union[None, str]): tags (list[str]): details (Any): refined_banner (Union[Unset, RefinedAdBanner]): """ uuid: UUID title: Union[None, str] type_: Type0D9Enum reward_amount: int content: str contents: list["AdContent"] refined_contents: list["RefinedAdContent"] description: Union[None, str] location: Union["AdPublicLocationType0", None] location_is_approximate: bool banner: Union[None, str] address: Union[None, str] url: Union[None, str] tags: list[str] details: Any refined_banner: Union[Unset, "RefinedAdBanner"] = UNSET additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> dict[str, Any]: from .ad_public_location_type_0 import AdPublicLocationType0 uuid = str(self.uuid) title: Union[None, str] title = self.title type_ = self.type_.value reward_amount = self.reward_amount content = self.content contents = [] for contents_item_data in self.contents: contents_item = contents_item_data.to_dict() contents.append(contents_item) refined_contents = [] for refined_contents_item_data in self.refined_contents: refined_contents_item = refined_contents_item_data.to_dict() refined_contents.append(refined_contents_item) description: Union[None, str] description = self.description location: Union[None, dict[str, Any]] if isinstance(self.location, AdPublicLocationType0): location = self.location.to_dict() else: location = self.location location_is_approximate = self.location_is_approximate banner: Union[None, str] banner = self.banner address: Union[None, str] address = self.address url: Union[None, str] url = self.url tags = self.tags details = self.details refined_banner: Union[Unset, dict[str, Any]] = UNSET if not isinstance(self.refined_banner, Unset): refined_banner = self.refined_banner.to_dict() field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { "uuid": uuid, "title": title, "type": type_, "reward_amount": reward_amount, "content": content, "contents": contents, "refined_contents": refined_contents, "description": description, "location": location, "location_is_approximate": location_is_approximate, "banner": banner, "address": address, "url": url, "tags": tags, "details": details, } ) if refined_banner is not UNSET: field_dict["refined_banner"] = refined_banner return field_dict @classmethod def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from .ad_content import AdContent from .ad_public_location_type_0 import AdPublicLocationType0 from .refined_ad_banner import RefinedAdBanner from .refined_ad_content import RefinedAdContent d = dict(src_dict) uuid = UUID(d.pop("uuid")) def _parse_title(data: object) -> Union[None, str]: if data is None: return data return cast(Union[None, str], data) title = _parse_title(d.pop("title")) type_ = Type0D9Enum(d.pop("type")) reward_amount = d.pop("reward_amount") content = d.pop("content") contents = [] _contents = d.pop("contents") for contents_item_data in _contents: contents_item = AdContent.from_dict(contents_item_data) contents.append(contents_item) refined_contents = [] _refined_contents = d.pop("refined_contents") for refined_contents_item_data in _refined_contents: refined_contents_item = RefinedAdContent.from_dict(refined_contents_item_data) refined_contents.append(refined_contents_item) def _parse_description(data: object) -> Union[None, str]: if data is None: return data return cast(Union[None, str], data) description = _parse_description(d.pop("description")) def _parse_location(data: object) -> Union["AdPublicLocationType0", None]: if data is None: return data try: if not isinstance(data, dict): raise TypeError() location_type_0 = AdPublicLocationType0.from_dict(data) return location_type_0 except: # noqa: E722 pass return cast(Union["AdPublicLocationType0", None], data) location = _parse_location(d.pop("location")) location_is_approximate = d.pop("location_is_approximate") def _parse_banner(data: object) -> Union[None, str]: if data is None: return data return cast(Union[None, str], data) banner = _parse_banner(d.pop("banner")) def _parse_address(data: object) -> Union[None, str]: if data is None: return data return cast(Union[None, str], data) address = _parse_address(d.pop("address")) def _parse_url(data: object) -> Union[None, str]: if data is None: return data return cast(Union[None, str], data) url = _parse_url(d.pop("url")) tags = cast(list[str], d.pop("tags")) details = d.pop("details") _refined_banner = d.pop("refined_banner", UNSET) refined_banner: Union[Unset, RefinedAdBanner] if isinstance(_refined_banner, Unset): refined_banner = UNSET else: refined_banner = RefinedAdBanner.from_dict(_refined_banner) ad_public = cls( uuid=uuid, title=title, type_=type_, reward_amount=reward_amount, content=content, contents=contents, refined_contents=refined_contents, description=description, location=location, location_is_approximate=location_is_approximate, banner=banner, address=address, url=url, tags=tags, details=details, refined_banner=refined_banner, ) ad_public.additional_properties = d return ad_public @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