Skip to main content

wave_api/inputs/
account.rs

1use serde::Serialize;
2
3use crate::enums::{AccountSubtypeValue, CurrencyCode};
4
5/// Input for creating an account.
6#[derive(Debug, Clone, Serialize)]
7#[serde(rename_all = "camelCase")]
8pub struct AccountCreateInput {
9    pub business_id: String,
10    pub name: String,
11    pub subtype: AccountSubtypeValue,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub currency: Option<CurrencyCode>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub description: Option<String>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub display_id: Option<String>,
18}
19
20impl AccountCreateInput {
21    pub fn new(
22        business_id: impl Into<String>,
23        name: impl Into<String>,
24        subtype: AccountSubtypeValue,
25    ) -> Self {
26        Self {
27            business_id: business_id.into(),
28            name: name.into(),
29            subtype,
30            currency: None,
31            description: None,
32            display_id: None,
33        }
34    }
35
36    pub fn currency(mut self, v: CurrencyCode) -> Self {
37        self.currency = Some(v);
38        self
39    }
40    pub fn description(mut self, v: impl Into<String>) -> Self {
41        self.description = Some(v.into());
42        self
43    }
44    pub fn display_id(mut self, v: impl Into<String>) -> Self {
45        self.display_id = Some(v.into());
46        self
47    }
48}
49
50/// Input for patching an account.
51#[derive(Debug, Clone, Serialize)]
52#[serde(rename_all = "camelCase")]
53pub struct AccountPatchInput {
54    pub id: String,
55    pub sequence: i64,
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub name: Option<String>,
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub description: Option<String>,
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub display_id: Option<String>,
62}
63
64impl AccountPatchInput {
65    pub fn new(id: impl Into<String>, sequence: i64) -> Self {
66        Self {
67            id: id.into(),
68            sequence,
69            name: None,
70            description: None,
71            display_id: None,
72        }
73    }
74
75    pub fn name(mut self, v: impl Into<String>) -> Self {
76        self.name = Some(v.into());
77        self
78    }
79    pub fn description(mut self, v: impl Into<String>) -> Self {
80        self.description = Some(v.into());
81        self
82    }
83}
84
85/// Input for archiving an account.
86#[derive(Debug, Clone, Serialize)]
87#[serde(rename_all = "camelCase")]
88pub struct AccountArchiveInput {
89    pub id: String,
90}
91
92impl AccountArchiveInput {
93    pub fn new(id: impl Into<String>) -> Self {
94        Self { id: id.into() }
95    }
96}