crm-backend/utils/clients/gooyal_advertising_client/models/ad.py
2026-06-07 11:34:17 +03:30

337 lines
9.9 KiB
Python

import datetime
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 dateutil.parser import isoparse
from .type_0d9_enum import Type0D9Enum
from ..types import UNSET, Unset
if TYPE_CHECKING:
from .ad_content import AdContent
from .ad_location_type_0 import AdLocationType0
from .refined_ad_banner import RefinedAdBanner
from .refined_ad_content import RefinedAdContent
T = TypeVar("T", bound="Ad")
@_attrs_define
class Ad:
"""
Attributes:
uuid (UUID):
title (Union[None, str]):
type_ (Type0D9Enum): * `1` - BILLBOARD
* `2` - CAPTURED_BILLBOARD
* `99` - PROMOTION
* `100` - CONSTANT
details (Any):
content (str):
contents (list['AdContent']):
refined_contents (list['RefinedAdContent']):
description (Union[None, str]):
location (Union['AdLocationType0', None]):
location_is_approximate (bool):
banner (Union[None, str]):
reward_amount (int):
reward_count (int):
address (Union[None, str]):
url (Union[None, str]):
tags (list[str]):
created_at (datetime.datetime):
updated_at (datetime.datetime):
display_time (str):
status (str):
user_uuid (UUID):
comments_count (str):
likes_count (str):
refined_banner (Union[Unset, RefinedAdBanner]):
"""
uuid: UUID
title: Union[None, str]
type_: Type0D9Enum
details: Any
content: str
contents: list["AdContent"]
refined_contents: list["RefinedAdContent"]
description: Union[None, str]
location: Union["AdLocationType0", None]
location_is_approximate: bool
banner: Union[None, str]
reward_amount: int
reward_count: int
address: Union[None, str]
url: Union[None, str]
tags: list[str]
created_at: datetime.datetime
updated_at: datetime.datetime
display_time: str
status: str
user_uuid: UUID
comments_count: str
likes_count: str
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_location_type_0 import AdLocationType0
uuid = str(self.uuid)
title: Union[None, str]
title = self.title
type_ = self.type_.value
details = self.details
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, AdLocationType0):
location = self.location.to_dict()
else:
location = self.location
location_is_approximate = self.location_is_approximate
banner: Union[None, str]
banner = self.banner
reward_amount = self.reward_amount
reward_count = self.reward_count
address: Union[None, str]
address = self.address
url: Union[None, str]
url = self.url
tags = self.tags
created_at = self.created_at.isoformat()
updated_at = self.updated_at.isoformat()
display_time = self.display_time
status = self.status
user_uuid = str(self.user_uuid)
comments_count = self.comments_count
likes_count = self.likes_count
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_,
"details": details,
"content": content,
"contents": contents,
"refined_contents": refined_contents,
"description": description,
"location": location,
"location_is_approximate": location_is_approximate,
"banner": banner,
"reward_amount": reward_amount,
"reward_count": reward_count,
"address": address,
"url": url,
"tags": tags,
"created_at": created_at,
"updated_at": updated_at,
"display_time": display_time,
"status": status,
"user_uuid": user_uuid,
"comments_count": comments_count,
"likes_count": likes_count,
}
)
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_location_type_0 import AdLocationType0
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"))
details = d.pop("details")
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["AdLocationType0", None]:
if data is None:
return data
try:
if not isinstance(data, dict):
raise TypeError()
location_type_0 = AdLocationType0.from_dict(data)
return location_type_0
except: # noqa: E722
pass
return cast(Union["AdLocationType0", 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"))
reward_amount = d.pop("reward_amount")
reward_count = d.pop("reward_count")
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"))
created_at = isoparse(d.pop("created_at"))
updated_at = isoparse(d.pop("updated_at"))
display_time = d.pop("display_time")
status = d.pop("status")
user_uuid = UUID(d.pop("user_uuid"))
comments_count = d.pop("comments_count")
likes_count = d.pop("likes_count")
_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 = cls(
uuid=uuid,
title=title,
type_=type_,
details=details,
content=content,
contents=contents,
refined_contents=refined_contents,
description=description,
location=location,
location_is_approximate=location_is_approximate,
banner=banner,
reward_amount=reward_amount,
reward_count=reward_count,
address=address,
url=url,
tags=tags,
created_at=created_at,
updated_at=updated_at,
display_time=display_time,
status=status,
user_uuid=user_uuid,
comments_count=comments_count,
likes_count=likes_count,
refined_banner=refined_banner,
)
ad.additional_properties = d
return ad
@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