import datetime from typing import ( TYPE_CHECKING, Any, BinaryIO, Dict, List, Optional, TextIO, Tuple, Type, TypeVar, Union, cast, ) import attr from dateutil.parser import isoparse from ..models.campaign_objective import CampaignObjective from ..models.campaign_platform import CampaignPlatform from ..models.campaign_status import CampaignStatus from ..types import UNSET, Unset T = TypeVar("T", bound="Campaign") @attr.s(auto_attribs=True) class Campaign: """ Attributes: id (str): name (str): vendor_id (int): subaccount_id (int): global_participant_id (str): status (CampaignStatus): An enumeration. objective (CampaignObjective): An enumeration. platforms (List[CampaignPlatform]): created_at (datetime.datetime): created_by (str): updated_at (datetime.datetime): updated_by (str): start_time (Union[Unset, None, datetime.datetime]): end_time (Union[Unset, None, datetime.datetime]): lifetime_budget (Union[Unset, None, float]): """ id: str name: str vendor_id: int subaccount_id: int global_participant_id: str status: CampaignStatus objective: CampaignObjective platforms: List[CampaignPlatform] created_at: datetime.datetime created_by: str updated_at: datetime.datetime updated_by: str start_time: Union[Unset, None, datetime.datetime] = UNSET end_time: Union[Unset, None, datetime.datetime] = UNSET lifetime_budget: Union[Unset, None, float] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: id = self.id name = self.name vendor_id = self.vendor_id subaccount_id = self.subaccount_id global_participant_id = self.global_participant_id status = self.status.value objective = self.objective.value platforms = [] for platforms_item_data in self.platforms: platforms_item = platforms_item_data.value platforms.append(platforms_item) created_at = self.created_at.isoformat() created_by = self.created_by updated_at = self.updated_at.isoformat() updated_by = self.updated_by start_time: Union[Unset, None, str] = UNSET if not isinstance(self.start_time, Unset): start_time = self.start_time.isoformat() if self.start_time else None end_time: Union[Unset, None, str] = UNSET if not isinstance(self.end_time, Unset): end_time = self.end_time.isoformat() if self.end_time else None lifetime_budget = self.lifetime_budget field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { "id": id, "name": name, "vendorId": vendor_id, "subaccountId": subaccount_id, "globalParticipantId": global_participant_id, "status": status, "objective": objective, "platforms": platforms, "createdAt": created_at, "createdBy": created_by, "updatedAt": updated_at, "updatedBy": updated_by, } ) if start_time is not UNSET: field_dict["startTime"] = start_time if end_time is not UNSET: field_dict["endTime"] = end_time if lifetime_budget is not UNSET: field_dict["lifetimeBudget"] = lifetime_budget return field_dict @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() id = d.pop("id") name = d.pop("name") vendor_id = d.pop("vendorId") subaccount_id = d.pop("subaccountId") global_participant_id = d.pop("globalParticipantId") status = CampaignStatus(d.pop("status")) objective = CampaignObjective(d.pop("objective")) platforms = [] _platforms = d.pop("platforms") for platforms_item_data in _platforms: platforms_item = CampaignPlatform(platforms_item_data) platforms.append(platforms_item) created_at = isoparse(d.pop("createdAt")) created_by = d.pop("createdBy") updated_at = isoparse(d.pop("updatedAt")) updated_by = d.pop("updatedBy") _start_time = d.pop("startTime", UNSET) start_time: Union[Unset, None, datetime.datetime] if _start_time is None: start_time = None elif isinstance(_start_time, Unset): start_time = UNSET else: start_time = isoparse(_start_time) _end_time = d.pop("endTime", UNSET) end_time: Union[Unset, None, datetime.datetime] if _end_time is None: end_time = None elif isinstance(_end_time, Unset): end_time = UNSET else: end_time = isoparse(_end_time) lifetime_budget = d.pop("lifetimeBudget", UNSET) campaign = cls( id=id, name=name, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_id=global_participant_id, status=status, objective=objective, platforms=platforms, created_at=created_at, created_by=created_by, updated_at=updated_at, updated_by=updated_by, start_time=start_time, end_time=end_time, lifetime_budget=lifetime_budget, ) campaign.additional_properties = d return campaign @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