use serde::{Deserialize, Serialize};
use super::{
credit_applies_to::CreditAppliesTo, credit_grant_id::CreditGrantId,
credit_grant_source::CreditGrantSource, credit_grant_type::CreditGrantType,
credit_note_id::CreditNoteId, customer_id::CustomerId, invoice_id::InvoiceId,
ledger_entry_id::LedgerEntryId,
};
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[non_exhaustive]
pub struct WalletFundedEventData {
pub amount: i64,
pub applicable_product_ids: Vec<String>,
pub applies_to: CreditAppliesTo,
pub credit_grant_id: CreditGrantId,
#[serde(skip_serializing_if = "Option::is_none")]
pub credit_note_id: Option<CreditNoteId>,
#[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 grant_type: CreditGrantType,
#[serde(skip_serializing_if = "Option::is_none")]
pub invoice_id: Option<InvoiceId>,
pub ledger_entry_id: LedgerEntryId,
pub source: CreditGrantSource,
#[serde(skip_serializing_if = "Option::is_none")]
pub subscription_id: Option<String>,
#[serde(flatten)]
pub extra: serde_json::Map<String, serde_json::Value>,
}
impl WalletFundedEventData {
#[must_use]
pub fn new(
amount: i64,
applicable_product_ids: Vec<String>,
applies_to: CreditAppliesTo,
credit_grant_id: impl Into<CreditGrantId>,
customer_id: impl Into<CustomerId>,
grant_type: CreditGrantType,
ledger_entry_id: impl Into<LedgerEntryId>,
source: CreditGrantSource,
) -> Self {
Self {
amount,
applicable_product_ids,
applies_to,
credit_grant_id: credit_grant_id.into(),
credit_note_id: None,
credit_unit: None,
credit_unit_precision: None,
currency: None,
customer_id: customer_id.into(),
grant_type,
invoice_id: None,
ledger_entry_id: ledger_entry_id.into(),
source,
subscription_id: None,
extra: serde_json::Map::new(),
}
}
}