1use serde::{Deserialize, Serialize};
2
3use crate::models::{ChargeModel, FixedChargeModel, PaginationParams};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct CreateChargeInput {
10 pub billable_metric_id: String,
12 pub charge_model: ChargeModel,
14 #[serde(skip_serializing_if = "Option::is_none")]
16 pub code: Option<String>,
17 #[serde(skip_serializing_if = "Option::is_none")]
19 pub invoice_display_name: Option<String>,
20 #[serde(skip_serializing_if = "Option::is_none")]
22 pub pay_in_advance: Option<bool>,
23 #[serde(skip_serializing_if = "Option::is_none")]
25 pub invoiceable: Option<bool>,
26 #[serde(skip_serializing_if = "Option::is_none")]
28 pub prorated: Option<bool>,
29 #[serde(skip_serializing_if = "Option::is_none")]
31 pub min_amount_cents: Option<i64>,
32 #[serde(skip_serializing_if = "Option::is_none")]
34 pub properties: Option<serde_json::Value>,
35 #[serde(skip_serializing_if = "Option::is_none")]
37 pub filters: Option<Vec<ChargeFilterInputValue>>,
38 #[serde(skip_serializing_if = "Option::is_none")]
40 pub tax_codes: Option<Vec<String>>,
41 #[serde(skip_serializing_if = "Option::is_none")]
43 pub regroup_paid_fees: Option<String>,
44 #[serde(skip_serializing_if = "Option::is_none")]
46 pub applied_pricing_unit: Option<serde_json::Value>,
47 #[serde(skip_serializing_if = "Option::is_none")]
49 pub accepts_target_wallet: Option<bool>,
50 #[serde(skip_serializing_if = "Option::is_none")]
52 pub cascade_updates: Option<bool>,
53}
54
55impl CreateChargeInput {
56 pub fn new(billable_metric_id: String, charge_model: ChargeModel) -> Self {
57 Self {
58 billable_metric_id,
59 charge_model,
60 code: None,
61 invoice_display_name: None,
62 pay_in_advance: None,
63 invoiceable: None,
64 prorated: None,
65 min_amount_cents: None,
66 properties: None,
67 filters: None,
68 tax_codes: None,
69 regroup_paid_fees: None,
70 applied_pricing_unit: None,
71 accepts_target_wallet: None,
72 cascade_updates: None,
73 }
74 }
75
76 pub fn with_code(mut self, code: String) -> Self {
77 self.code = Some(code);
78 self
79 }
80
81 pub fn with_properties(mut self, properties: serde_json::Value) -> Self {
82 self.properties = Some(properties);
83 self
84 }
85
86 pub fn with_tax_codes(mut self, tax_codes: Vec<String>) -> Self {
87 self.tax_codes = Some(tax_codes);
88 self
89 }
90}
91
92#[derive(Debug, Clone, Default, Serialize, Deserialize)]
94pub struct UpdateChargeInput {
95 #[serde(skip_serializing_if = "Option::is_none")]
96 pub invoice_display_name: Option<String>,
97 #[serde(skip_serializing_if = "Option::is_none")]
98 pub pay_in_advance: Option<bool>,
99 #[serde(skip_serializing_if = "Option::is_none")]
100 pub invoiceable: Option<bool>,
101 #[serde(skip_serializing_if = "Option::is_none")]
102 pub prorated: Option<bool>,
103 #[serde(skip_serializing_if = "Option::is_none")]
104 pub min_amount_cents: Option<i64>,
105 #[serde(skip_serializing_if = "Option::is_none")]
106 pub properties: Option<serde_json::Value>,
107 #[serde(skip_serializing_if = "Option::is_none")]
108 pub filters: Option<Vec<ChargeFilterInputValue>>,
109 #[serde(skip_serializing_if = "Option::is_none")]
110 pub tax_codes: Option<Vec<String>>,
111 #[serde(skip_serializing_if = "Option::is_none")]
112 pub applied_pricing_unit: Option<serde_json::Value>,
113 #[serde(skip_serializing_if = "Option::is_none")]
114 pub accepts_target_wallet: Option<bool>,
115 #[serde(skip_serializing_if = "Option::is_none")]
116 pub cascade_updates: Option<bool>,
117}
118
119impl UpdateChargeInput {
120 pub fn new() -> Self {
121 Self::default()
122 }
123}
124
125#[derive(Debug, Clone, Serialize, Deserialize)]
127pub struct ChargeFilterInputValue {
128 #[serde(skip_serializing_if = "Option::is_none")]
129 pub invoice_display_name: Option<String>,
130 #[serde(skip_serializing_if = "Option::is_none")]
131 pub properties: Option<serde_json::Value>,
132 #[serde(skip_serializing_if = "Option::is_none")]
133 pub values: Option<serde_json::Value>,
134 #[serde(skip_serializing_if = "Option::is_none")]
135 pub cascade_updates: Option<bool>,
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
142pub struct CreateFixedChargeInput {
143 pub add_on_id: String,
145 pub charge_model: FixedChargeModel,
147 #[serde(skip_serializing_if = "Option::is_none")]
149 pub code: Option<String>,
150 #[serde(skip_serializing_if = "Option::is_none")]
152 pub invoice_display_name: Option<String>,
153 #[serde(skip_serializing_if = "Option::is_none")]
155 pub pay_in_advance: Option<bool>,
156 #[serde(skip_serializing_if = "Option::is_none")]
158 pub prorated: Option<bool>,
159 #[serde(skip_serializing_if = "Option::is_none")]
161 pub units: Option<f64>,
162 #[serde(skip_serializing_if = "Option::is_none")]
164 pub apply_units_immediately: Option<bool>,
165 #[serde(skip_serializing_if = "Option::is_none")]
167 pub properties: Option<serde_json::Value>,
168 #[serde(skip_serializing_if = "Option::is_none")]
170 pub tax_codes: Option<Vec<String>>,
171 #[serde(skip_serializing_if = "Option::is_none")]
173 pub cascade_updates: Option<bool>,
174}
175
176impl CreateFixedChargeInput {
177 pub fn new(add_on_id: String, charge_model: FixedChargeModel) -> Self {
178 Self {
179 add_on_id,
180 charge_model,
181 code: None,
182 invoice_display_name: None,
183 pay_in_advance: None,
184 prorated: None,
185 units: None,
186 apply_units_immediately: None,
187 properties: None,
188 tax_codes: None,
189 cascade_updates: None,
190 }
191 }
192
193 pub fn with_code(mut self, code: String) -> Self {
194 self.code = Some(code);
195 self
196 }
197
198 pub fn with_units(mut self, units: f64) -> Self {
199 self.units = Some(units);
200 self
201 }
202}
203
204#[derive(Debug, Clone, Default, Serialize, Deserialize)]
206pub struct UpdateFixedChargeInput {
207 #[serde(skip_serializing_if = "Option::is_none")]
208 pub invoice_display_name: Option<String>,
209 #[serde(skip_serializing_if = "Option::is_none")]
210 pub units: Option<f64>,
211 #[serde(skip_serializing_if = "Option::is_none")]
212 pub apply_units_immediately: Option<bool>,
213 #[serde(skip_serializing_if = "Option::is_none")]
214 pub properties: Option<serde_json::Value>,
215 #[serde(skip_serializing_if = "Option::is_none")]
216 pub tax_codes: Option<Vec<String>>,
217 #[serde(skip_serializing_if = "Option::is_none")]
218 pub cascade_updates: Option<bool>,
219}
220
221impl UpdateFixedChargeInput {
222 pub fn new() -> Self {
223 Self::default()
224 }
225}
226
227#[derive(Debug, Clone, Default, Serialize, Deserialize)]
231pub struct ChargeFilterInput {
232 #[serde(skip_serializing_if = "Option::is_none")]
233 pub invoice_display_name: Option<String>,
234 #[serde(skip_serializing_if = "Option::is_none")]
235 pub properties: Option<serde_json::Value>,
236 #[serde(skip_serializing_if = "Option::is_none")]
237 pub values: Option<serde_json::Value>,
238 #[serde(skip_serializing_if = "Option::is_none")]
239 pub cascade_updates: Option<bool>,
240}
241
242impl ChargeFilterInput {
243 pub fn new() -> Self {
244 Self::default()
245 }
246}
247
248#[derive(Debug, Clone)]
252pub struct ListPlanChargesRequest {
253 pub plan_code: String,
254 pub pagination: PaginationParams,
255}
256
257impl ListPlanChargesRequest {
258 pub fn new(plan_code: String) -> Self {
259 Self {
260 plan_code,
261 pagination: PaginationParams::default(),
262 }
263 }
264
265 pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
266 self.pagination = pagination;
267 self
268 }
269
270 pub fn to_query_params(&self) -> Vec<(&str, String)> {
271 self.pagination.to_query_params()
272 }
273}
274
275#[derive(Debug, Clone)]
277pub struct GetPlanChargeRequest {
278 pub plan_code: String,
279 pub charge_code: String,
280}
281
282impl GetPlanChargeRequest {
283 pub fn new(plan_code: String, charge_code: String) -> Self {
284 Self {
285 plan_code,
286 charge_code,
287 }
288 }
289}
290
291#[derive(Debug, Clone, Serialize)]
293pub struct CreatePlanChargeRequest {
294 #[serde(skip)]
295 pub plan_code: String,
296 pub charge: CreateChargeInput,
297}
298
299impl CreatePlanChargeRequest {
300 pub fn new(plan_code: String, input: CreateChargeInput) -> Self {
301 Self {
302 plan_code,
303 charge: input,
304 }
305 }
306}
307
308#[derive(Debug, Clone, Serialize)]
310pub struct UpdatePlanChargeRequest {
311 #[serde(skip)]
312 pub plan_code: String,
313 #[serde(skip)]
314 pub charge_code: String,
315 pub charge: UpdateChargeInput,
316}
317
318impl UpdatePlanChargeRequest {
319 pub fn new(plan_code: String, charge_code: String, input: UpdateChargeInput) -> Self {
320 Self {
321 plan_code,
322 charge_code,
323 charge: input,
324 }
325 }
326}
327
328#[derive(Debug, Clone)]
330pub struct DeletePlanChargeRequest {
331 pub plan_code: String,
332 pub charge_code: String,
333 pub cascade_updates: Option<bool>,
334}
335
336impl DeletePlanChargeRequest {
337 pub fn new(plan_code: String, charge_code: String) -> Self {
338 Self {
339 plan_code,
340 charge_code,
341 cascade_updates: None,
342 }
343 }
344
345 pub fn with_cascade_updates(mut self, cascade_updates: bool) -> Self {
346 self.cascade_updates = Some(cascade_updates);
347 self
348 }
349
350 pub fn to_query_params(&self) -> Vec<(&str, String)> {
351 let mut params = Vec::new();
352 if let Some(cascade) = self.cascade_updates {
353 params.push(("cascade_updates", cascade.to_string()));
354 }
355 params
356 }
357}
358
359#[derive(Debug, Clone)]
363pub struct ListPlanFixedChargesRequest {
364 pub plan_code: String,
365 pub pagination: PaginationParams,
366}
367
368impl ListPlanFixedChargesRequest {
369 pub fn new(plan_code: String) -> Self {
370 Self {
371 plan_code,
372 pagination: PaginationParams::default(),
373 }
374 }
375
376 pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
377 self.pagination = pagination;
378 self
379 }
380
381 pub fn to_query_params(&self) -> Vec<(&str, String)> {
382 self.pagination.to_query_params()
383 }
384}
385
386#[derive(Debug, Clone)]
388pub struct GetPlanFixedChargeRequest {
389 pub plan_code: String,
390 pub fixed_charge_code: String,
391}
392
393impl GetPlanFixedChargeRequest {
394 pub fn new(plan_code: String, fixed_charge_code: String) -> Self {
395 Self {
396 plan_code,
397 fixed_charge_code,
398 }
399 }
400}
401
402#[derive(Debug, Clone, Serialize)]
404pub struct CreatePlanFixedChargeRequest {
405 #[serde(skip)]
406 pub plan_code: String,
407 pub fixed_charge: CreateFixedChargeInput,
408}
409
410impl CreatePlanFixedChargeRequest {
411 pub fn new(plan_code: String, input: CreateFixedChargeInput) -> Self {
412 Self {
413 plan_code,
414 fixed_charge: input,
415 }
416 }
417}
418
419#[derive(Debug, Clone, Serialize)]
421pub struct UpdatePlanFixedChargeRequest {
422 #[serde(skip)]
423 pub plan_code: String,
424 #[serde(skip)]
425 pub fixed_charge_code: String,
426 pub fixed_charge: UpdateFixedChargeInput,
427}
428
429impl UpdatePlanFixedChargeRequest {
430 pub fn new(
431 plan_code: String,
432 fixed_charge_code: String,
433 input: UpdateFixedChargeInput,
434 ) -> Self {
435 Self {
436 plan_code,
437 fixed_charge_code,
438 fixed_charge: input,
439 }
440 }
441}
442
443#[derive(Debug, Clone)]
445pub struct DeletePlanFixedChargeRequest {
446 pub plan_code: String,
447 pub fixed_charge_code: String,
448 pub cascade_updates: Option<bool>,
449}
450
451impl DeletePlanFixedChargeRequest {
452 pub fn new(plan_code: String, fixed_charge_code: String) -> Self {
453 Self {
454 plan_code,
455 fixed_charge_code,
456 cascade_updates: None,
457 }
458 }
459
460 pub fn with_cascade_updates(mut self, cascade_updates: bool) -> Self {
461 self.cascade_updates = Some(cascade_updates);
462 self
463 }
464
465 pub fn to_query_params(&self) -> Vec<(&str, String)> {
466 let mut params = Vec::new();
467 if let Some(cascade) = self.cascade_updates {
468 params.push(("cascade_updates", cascade.to_string()));
469 }
470 params
471 }
472}
473
474#[derive(Debug, Clone)]
478pub struct ListPlanChargeFiltersRequest {
479 pub plan_code: String,
480 pub charge_code: String,
481 pub pagination: PaginationParams,
482}
483
484impl ListPlanChargeFiltersRequest {
485 pub fn new(plan_code: String, charge_code: String) -> Self {
486 Self {
487 plan_code,
488 charge_code,
489 pagination: PaginationParams::default(),
490 }
491 }
492
493 pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
494 self.pagination = pagination;
495 self
496 }
497
498 pub fn to_query_params(&self) -> Vec<(&str, String)> {
499 self.pagination.to_query_params()
500 }
501}
502
503#[derive(Debug, Clone)]
505pub struct GetPlanChargeFilterRequest {
506 pub plan_code: String,
507 pub charge_code: String,
508 pub filter_id: String,
509}
510
511impl GetPlanChargeFilterRequest {
512 pub fn new(plan_code: String, charge_code: String, filter_id: String) -> Self {
513 Self {
514 plan_code,
515 charge_code,
516 filter_id,
517 }
518 }
519}
520
521#[derive(Debug, Clone, Serialize)]
523pub struct CreatePlanChargeFilterRequest {
524 #[serde(skip)]
525 pub plan_code: String,
526 #[serde(skip)]
527 pub charge_code: String,
528 pub filter: ChargeFilterInput,
529}
530
531impl CreatePlanChargeFilterRequest {
532 pub fn new(plan_code: String, charge_code: String, input: ChargeFilterInput) -> Self {
533 Self {
534 plan_code,
535 charge_code,
536 filter: input,
537 }
538 }
539}
540
541#[derive(Debug, Clone, Serialize)]
543pub struct UpdatePlanChargeFilterRequest {
544 #[serde(skip)]
545 pub plan_code: String,
546 #[serde(skip)]
547 pub charge_code: String,
548 #[serde(skip)]
549 pub filter_id: String,
550 pub filter: ChargeFilterInput,
551}
552
553impl UpdatePlanChargeFilterRequest {
554 pub fn new(
555 plan_code: String,
556 charge_code: String,
557 filter_id: String,
558 input: ChargeFilterInput,
559 ) -> Self {
560 Self {
561 plan_code,
562 charge_code,
563 filter_id,
564 filter: input,
565 }
566 }
567}
568
569#[derive(Debug, Clone)]
571pub struct DeletePlanChargeFilterRequest {
572 pub plan_code: String,
573 pub charge_code: String,
574 pub filter_id: String,
575 pub cascade_updates: Option<bool>,
576}
577
578impl DeletePlanChargeFilterRequest {
579 pub fn new(plan_code: String, charge_code: String, filter_id: String) -> Self {
580 Self {
581 plan_code,
582 charge_code,
583 filter_id,
584 cascade_updates: None,
585 }
586 }
587
588 pub fn with_cascade_updates(mut self, cascade_updates: bool) -> Self {
589 self.cascade_updates = Some(cascade_updates);
590 self
591 }
592
593 pub fn to_query_params(&self) -> Vec<(&str, String)> {
594 let mut params = Vec::new();
595 if let Some(cascade) = self.cascade_updates {
596 params.push(("cascade_updates", cascade.to_string()));
597 }
598 params
599 }
600}