use serde::{Deserialize, Serialize};
use super::{
credit_note_id::CreditNoteId, customer_id::CustomerId, invoice_id::InvoiceId,
payment_transaction_id::PaymentTransactionId,
};
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[non_exhaustive]
pub struct WalletCreditRecoveredEventData {
pub cause: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub credit_note_id: Option<CreditNoteId>,
pub credit_recovered: i64,
#[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>,
pub credit_unrecovered_total: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub currency: Option<String>,
pub customer_id: CustomerId,
#[serde(skip_serializing_if = "Option::is_none")]
pub invoice_id: Option<InvoiceId>,
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_id: Option<PaymentTransactionId>,
#[serde(flatten)]
pub extra: serde_json::Map<String, serde_json::Value>,
}
impl WalletCreditRecoveredEventData {
#[must_use]
pub fn new(
cause: impl Into<String>,
credit_recovered: i64,
credit_unrecovered_total: i64,
customer_id: impl Into<CustomerId>,
) -> Self {
Self {
cause: cause.into(),
credit_note_id: None,
credit_recovered,
credit_unit: None,
credit_unit_precision: None,
credit_unrecovered_total,
currency: None,
customer_id: customer_id.into(),
invoice_id: None,
payment_id: None,
extra: serde_json::Map::new(),
}
}
}