tmflib/tmf666/
settlement_account.rs

1//! Billing Account Module
2
3use serde::{Deserialize, Serialize};
4
5use crate::common::{contact::Contact, money::Money, related_party::RelatedParty};
6use crate::{DateTime, HasDescription, HasId, HasLastUpdate, HasName};
7use tmflib_derive::{HasDescription, HasId, HasLastUpdate, HasName};
8
9use super::{
10    financial_account::FinancialAccountRef, AccountBalance, AccountRef, AccountTaxExemption,
11    PaymentMethodRef, PaymentPlan, MOD_PATH,
12};
13
14const CLASS_PATH: &str = "account";
15
16/// Billing Account
17#[derive(
18    Clone, Debug, Default, Deserialize, HasId, HasName, HasLastUpdate, HasDescription, Serialize,
19)]
20#[serde(rename_all = "camelCase")]
21pub struct SettlementAccount {
22    #[serde(skip_serializing_if = "Option::is_none")]
23    account_type: Option<String>,
24    #[serde(skip_serializing_if = "Option::is_none")]
25    credit_limit: Option<Money>,
26    /// Account Description
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub description: Option<String>,
29    /// Unique Identifier
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub id: Option<String>,
32    /// HTTP URI
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub href: Option<String>,
35    #[serde(skip_serializing_if = "Option::is_none")]
36    last_modified: Option<DateTime>,
37    #[serde(skip_serializing_if = "Option::is_none")]
38    name: Option<String>,
39    #[serde(skip_serializing_if = "Option::is_none")]
40    payment_status: Option<String>,
41    #[serde(skip_serializing_if = "Option::is_none")]
42    rating_type: Option<String>,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    state: Option<String>,
45    #[serde(skip_serializing_if = "Option::is_none")]
46    last_update: Option<DateTime>,
47    related_party: Vec<RelatedParty>,
48    #[serde(skip_serializing_if = "Option::is_none")]
49    contact: Option<Vec<Contact>>,
50    #[serde(skip_serializing_if = "Option::is_none")]
51    account_balance: Option<Vec<AccountBalance>>,
52    #[serde(skip_serializing_if = "Option::is_none")]
53    tax_exemption: Option<Vec<AccountTaxExemption>>,
54    #[serde(skip_serializing_if = "Option::is_none")]
55    financial_account: Option<FinancialAccountRef>,
56    #[serde(skip_serializing_if = "Option::is_none")]
57    payment_plan: Option<Vec<PaymentPlan>>,
58    #[serde(skip_serializing_if = "Option::is_none")]
59    default_payment_method: Option<PaymentMethodRef>,
60}
61
62impl SettlementAccount {
63    /// Create new Billing Account
64    pub fn new(name: impl Into<String>) -> SettlementAccount {
65        SettlementAccount {
66            name: Some(name.into()),
67            ..SettlementAccount::create()
68        }
69    }
70}
71
72impl From<SettlementAccount> for AccountRef {
73    fn from(value: SettlementAccount) -> Self {
74        AccountRef {
75            id: value.get_id(),
76            href: value.get_href(),
77            name: value.get_name(),
78            description: value.description.clone(),
79        }
80    }
81}
82
83/// Billing Account Reference
84#[derive(Clone, Debug, Default, Deserialize, Serialize)]
85pub struct BillingAccountRef {
86    /// Referenced Id
87    id: String,
88    /// Referenced HREF
89    href: String,
90    /// Referenced Name
91    name: String,
92}
93
94#[cfg(test)]
95mod test {
96    use super::*;
97    use crate::HasId;
98
99    const ACCOUNT_NAME: &str = "SettlementAccount";
100
101    #[test]
102    fn test_settlement_account_new_name() {
103        let account = SettlementAccount::new(ACCOUNT_NAME);
104
105        assert_eq!(account.name, Some(ACCOUNT_NAME.into()));
106    }
107
108    #[test]
109    fn test_accountref_from_settlementaccount() {
110        let settlementaccount = SettlementAccount::new(ACCOUNT_NAME);
111
112        let accountref = AccountRef::from(settlementaccount.clone());
113
114        assert_eq!(accountref.id, settlementaccount.get_id());
115        assert_eq!(accountref.href, settlementaccount.get_href());
116        assert_eq!(accountref.name, settlementaccount.get_name());
117    }
118}