1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use crate::{impl_base_query_params, QueryParams};
use bigdecimal::BigDecimal;
use serde_derive::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct Paging {
  pub before: Option<String>,
  pub after: Option<String>,
}

#[derive(Debug, Default)]
pub struct BasePageParams {
  params: QueryParams,
}

impl BasePageParams {
  pub(crate) const fn new() -> Self {
    Self { params: Vec::new() }
  }

  pub(crate) fn limit(&mut self, limit: u16) -> &mut Self {
    self.params.push(("limit".to_owned(), format!("{limit}")));
    self
  }

  #[allow(clippy::unnecessary_wraps)]
  pub(crate) fn build(&self) -> std::result::Result<QueryParams, crate::error::ParamError> {
    Ok(Vec::clone(&self.params))
  }
}

#[derive(Debug, Default)]
pub struct PagingAddressRequestBuilder {
  params: QueryParams,
  base: BasePageParams,
}

impl_base_query_params!(PagingAddressRequestBuilder);

#[derive(Debug, Default)]
pub struct PagingVaultRequestBuilder {
  params: QueryParams,
  base: BasePageParams,
}

impl_base_query_params!(PagingVaultRequestBuilder);

impl PagingAddressRequestBuilder {
  pub fn before(&mut self, t: &str) -> &mut Self {
    self.params.push(("before".to_owned(), String::from(t)));
    self
  }

  pub fn after(&mut self, t: &str) -> &mut Self {
    self.params.push(("before".to_owned(), String::from(t)));
    self
  }
}

impl PagingVaultRequestBuilder {
  pub fn min_threshold(&mut self, min: &BigDecimal) -> &mut Self {
    self.params.push(("minAmountThreshold".to_owned(), min.to_string()));
    self
  }

  pub fn name_prefix(&mut self, n: &str) -> &mut Self {
    self.params.push(("namePrefix".to_owned(), String::from(n)));
    self
  }

  pub fn name_suffix(&mut self, n: &str) -> &mut Self {
    self.params.push(("nameSuffix".to_owned(), String::from(n)));
    self
  }

  pub fn before(&mut self, t: &str) -> &mut Self {
    self.params.push(("before".to_owned(), String::from(t)));
    self
  }

  pub fn after(&mut self, t: &str) -> &mut Self {
    if !t.is_empty() {
      self.params.push(("after".to_owned(), String::from(t)));
    }
    self
  }
}