use serde::{Deserialize, Serialize};
use super::{
event_id::EventId, event_type::EventType, product_family_id::ProductFamilyId,
product_fee_type_enum::ProductFeeTypeEnum, product_id::ProductId,
};
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[non_exhaustive]
pub struct ProductEvent {
pub created_at: chrono::DateTime<chrono::Utc>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub fee_type: ProductFeeTypeEnum,
pub name: String,
pub product_family_id: ProductFamilyId,
pub product_id: ProductId,
pub id: EventId,
pub timestamp: chrono::DateTime<chrono::Utc>,
pub r#type: EventType,
#[serde(flatten)]
pub extra: serde_json::Map<String, serde_json::Value>,
}
impl ProductEvent {
#[must_use]
pub fn new(
created_at: chrono::DateTime<chrono::Utc>,
fee_type: ProductFeeTypeEnum,
name: impl Into<String>,
product_family_id: impl Into<ProductFamilyId>,
product_id: impl Into<ProductId>,
id: impl Into<EventId>,
timestamp: chrono::DateTime<chrono::Utc>,
r#type: EventType,
) -> Self {
Self {
created_at,
description: None,
fee_type,
name: name.into(),
product_family_id: product_family_id.into(),
product_id: product_id.into(),
id: id.into(),
timestamp,
r#type,
extra: serde_json::Map::new(),
}
}
}