coinbase_client/private_client/
report.rs1#[derive(serde::Serialize, Debug)]
3pub struct Report {
4 r#type: String,
5 start_date: String,
6 end_date: String,
7 product_id: Option<String>,
8 account_id: Option<String>,
9 format: Format,
10 email: Option<String>,
11}
12
13impl Report {
14 pub fn fills_builder(
16 start_date: &str,
17 end_date: &str,
18 product_id: &str,
19 ) -> impl SharedReportOptions + FillsReportOptions {
20 ReportBuilder {
21 r#type: "fills".to_string(),
22 start_date: start_date.to_string(),
23 end_date: end_date.to_string(),
24 product_id: Some(product_id.to_string()),
25 account_id: None,
26 format: Format::PDF,
27 email: None,
28 }
29 }
30
31 pub fn account_builder(
33 start_date: &str,
34 end_date: &str,
35 account_id: &str,
36 ) -> impl SharedReportOptions + AccountReportOptions {
37 ReportBuilder {
38 r#type: "account".to_string(),
39 start_date: start_date.to_string(),
40 end_date: end_date.to_string(),
41 product_id: None,
42 account_id: Some(account_id.to_string()),
43 format: Format::PDF,
44 email: None,
45 }
46 }
47}
48
49#[derive(Debug)]
51pub struct ReportBuilder {
52 r#type: String,
53 start_date: String,
54 end_date: String,
55 product_id: Option<String>,
56 account_id: Option<String>,
57 format: Format,
58 email: Option<String>,
59}
60
61impl ReportBuilder {
62 pub fn fills(
64 start_date: &str,
65 end_date: &str,
66 product_id: &str,
67 ) -> impl SharedReportOptions + FillsReportOptions {
68 Self {
69 r#type: "fills".to_string(),
70 start_date: start_date.to_string(),
71 end_date: end_date.to_string(),
72 product_id: Some(product_id.to_string()),
73 account_id: None,
74 format: Format::PDF,
75 email: None,
76 }
77 }
78
79 pub fn account(
81 start_date: &str,
82 end_date: &str,
83 account_id: &str,
84 ) -> impl SharedReportOptions + AccountReportOptions {
85 Self {
86 r#type: "account".to_string(),
87 start_date: start_date.to_string(),
88 end_date: end_date.to_string(),
89 product_id: None,
90 account_id: Some(account_id.to_string()),
91 format: Format::PDF,
92 email: None,
93 }
94 }
95}
96
97pub trait FillsReportOptions {
99 fn account_id(self, account_id: &str) -> Self;
100}
101
102impl FillsReportOptions for ReportBuilder {
103 fn account_id(mut self, account_id: &str) -> Self {
105 self.account_id = Some(account_id.to_string());
106 self
107 }
108}
109
110pub trait AccountReportOptions {
112 fn product_id(self, product_id: &str) -> Self;
113}
114
115impl AccountReportOptions for ReportBuilder {
116 fn product_id(mut self, product_id: &str) -> Self {
118 self.product_id = Some(product_id.to_string());
119 self
120 }
121}
122
123pub trait SharedReportOptions {
125 fn format(self, format: Format) -> Self;
126 fn email(self, email: &str) -> Self;
127 fn build(self) -> Report;
128}
129
130impl SharedReportOptions for ReportBuilder {
131 fn format(mut self, format: Format) -> Self {
133 self.format = format;
134 self
135 }
136
137 fn email(mut self, email: &str) -> Self {
139 self.email = Some(email.to_string());
140 self
141 }
142
143 fn build(self) -> Report {
145 Report {
146 r#type: self.r#type,
147 start_date: self.start_date,
148 end_date: self.end_date,
149 product_id: self.product_id,
150 account_id: self.account_id,
151 format: self.format,
152 email: self.email,
153 }
154 }
155}
156
157#[derive(Debug)]
159pub enum Format {
160 PDF,
161 CSV,
162}
163
164impl serde::Serialize for Format {
165 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
166 where
167 S: serde::ser::Serializer,
168 {
169 match self {
170 Self::PDF => serializer.serialize_str("pdf"),
171 Self::CSV => serializer.serialize_str("csv"),
172 }
173 }
174}