use serde::{Deserialize, Serialize};
use super::{
credit_applies_to::CreditAppliesTo, credit_grant_id::CreditGrantId,
credit_grant_lapse_reason::CreditGrantLapseReason, customer_id::CustomerId, event_id::EventId,
event_type::EventType, ledger_entry_id::LedgerEntryId,
};
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[non_exhaustive]
pub struct CreditGrantExpiredEvent {
pub applicable_product_ids: Vec<String>,
pub applies_to: CreditAppliesTo,
pub credit_grant_id: CreditGrantId,
#[serde(skip_serializing_if = "Option::is_none")]
pub credit_unit: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub credit_unit_precision: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub currency: Option<String>,
pub customer_id: CustomerId,
pub expired_amount: i64,
pub expired_at: chrono::DateTime<chrono::Utc>,
pub ledger_entry_id: LedgerEntryId,
pub reason: CreditGrantLapseReason,
#[serde(skip_serializing_if = "Option::is_none")]
pub subscription_id: 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 CreditGrantExpiredEvent {
#[must_use]
pub fn new(
applicable_product_ids: Vec<String>,
applies_to: CreditAppliesTo,
credit_grant_id: impl Into<CreditGrantId>,
customer_id: impl Into<CustomerId>,
expired_amount: i64,
expired_at: chrono::DateTime<chrono::Utc>,
ledger_entry_id: impl Into<LedgerEntryId>,
reason: CreditGrantLapseReason,
id: impl Into<EventId>,
timestamp: chrono::DateTime<chrono::Utc>,
r#type: EventType,
) -> Self {
Self {
applicable_product_ids,
applies_to,
credit_grant_id: credit_grant_id.into(),
credit_unit: None,
credit_unit_precision: None,
currency: None,
customer_id: customer_id.into(),
expired_amount,
expired_at,
ledger_entry_id: ledger_entry_id.into(),
reason,
subscription_id: None,
id: id.into(),
timestamp,
r#type,
extra: serde_json::Map::new(),
}
}
}