from collections.abc import Mapping from typing import Any, TypeVar, Union from attrs import define as _attrs_define from attrs import field as _attrs_field from .. import types from ..types import UNSET, Unset T = TypeVar("T", bound="PatchedPromotionCode") @_attrs_define class PatchedPromotionCode: """Serializer for PromotionCode model Attributes: event (Union[Unset, int]): event_id (Union[Unset, int]): id (Union[Unset, int]): name (Union[Unset, str]): name of the promotion that will be shown value (Union[Unset, str]): value of the code that users will have to enter to get the promotion """ event: Union[Unset, int] = UNSET event_id: Union[Unset, int] = UNSET id: Union[Unset, int] = UNSET name: Union[Unset, str] = UNSET value: Union[Unset, str] = UNSET additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> dict[str, Any]: event = self.event event_id = self.event_id id = self.id name = self.name value = self.value field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if event is not UNSET: field_dict["event"] = event if event_id is not UNSET: field_dict["event_id"] = event_id if id is not UNSET: field_dict["id"] = id if name is not UNSET: field_dict["name"] = name if value is not UNSET: field_dict["value"] = value return field_dict def to_multipart(self) -> types.RequestFiles: files: types.RequestFiles = [] if not isinstance(self.event, Unset): files.append(("event", (None, str(self.event).encode(), "text/plain"))) if not isinstance(self.event_id, Unset): files.append(("event_id", (None, str(self.event_id).encode(), "text/plain"))) if not isinstance(self.id, Unset): files.append(("id", (None, str(self.id).encode(), "text/plain"))) if not isinstance(self.name, Unset): files.append(("name", (None, str(self.name).encode(), "text/plain"))) if not isinstance(self.value, Unset): files.append(("value", (None, str(self.value).encode(), "text/plain"))) for prop_name, prop in self.additional_properties.items(): files.append((prop_name, (None, str(prop).encode(), "text/plain"))) return files @classmethod def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: d = dict(src_dict) event = d.pop("event", UNSET) event_id = d.pop("event_id", UNSET) id = d.pop("id", UNSET) name = d.pop("name", UNSET) value = d.pop("value", UNSET) patched_promotion_code = cls( event=event, event_id=event_id, id=id, name=name, value=value, ) patched_promotion_code.additional_properties = d return patched_promotion_code @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