use serde::{Deserialize, Serialize};
use super::{customer_id::CustomerId, event_id::EventId, event_type::EventType};
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[non_exhaustive]
pub struct CustomerEvent {
#[serde(skip_serializing_if = "Option::is_none")]
pub alias: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub billing_email: Option<String>,
pub currency: String,
pub custom_properties: serde_json::Value,
pub customer_id: CustomerId,
pub invoicing_emails: Vec<String>,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub phone: Option<String>,
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 CustomerEvent {
#[must_use]
pub fn new(
currency: impl Into<String>,
custom_properties: serde_json::Value,
customer_id: impl Into<CustomerId>,
invoicing_emails: Vec<String>,
name: impl Into<String>,
id: impl Into<EventId>,
timestamp: chrono::DateTime<chrono::Utc>,
r#type: EventType,
) -> Self {
Self {
alias: None,
billing_email: None,
currency: currency.into(),
custom_properties,
customer_id: customer_id.into(),
invoicing_emails,
name: name.into(),
phone: None,
id: id.into(),
timestamp,
r#type,
extra: serde_json::Map::new(),
}
}
}