ic_query/nns/node/report/model/
request.rs1use crate::nns::NnsInventoryCacheRequest;
2#[cfg(feature = "host")]
3use crate::nns::inventory::NnsInventoryListInput;
4
5#[derive(Clone, Debug, Eq, PartialEq)]
12pub struct NnsNodeListRequest {
13 pub cache: NnsInventoryCacheRequest,
14 pub source_endpoint: String,
15 pub now_unix_secs: u64,
16 pub filters: NnsNodeListFilters,
17}
18
19impl NnsNodeListRequest {
20 #[must_use]
21 pub fn new(
22 cache: NnsInventoryCacheRequest,
23 source_endpoint: impl Into<String>,
24 now_unix_secs: u64,
25 ) -> Self {
26 Self {
27 cache,
28 source_endpoint: source_endpoint.into(),
29 now_unix_secs,
30 filters: NnsNodeListFilters::default(),
31 }
32 }
33
34 #[must_use]
35 pub fn with_filters(mut self, filters: NnsNodeListFilters) -> Self {
36 self.filters = filters;
37 self
38 }
39
40 #[must_use]
41 pub fn with_subnet(mut self, subnet: impl Into<String>) -> Self {
42 self.filters.subnet = Some(subnet.into());
43 self
44 }
45
46 #[must_use]
47 pub fn with_subnet_kind(mut self, subnet_kind: impl Into<String>) -> Self {
48 self.filters.subnet_kind = Some(subnet_kind.into());
49 self
50 }
51
52 #[must_use]
53 pub fn with_data_center(mut self, data_center: impl Into<String>) -> Self {
54 self.filters.data_center = Some(data_center.into());
55 self
56 }
57
58 #[must_use]
59 pub fn with_node_provider(mut self, node_provider: impl Into<String>) -> Self {
60 self.filters.node_provider = Some(node_provider.into());
61 self
62 }
63
64 #[must_use]
65 pub fn with_node_operator(mut self, node_operator: impl Into<String>) -> Self {
66 self.filters.node_operator = Some(node_operator.into());
67 self
68 }
69}
70
71#[cfg(feature = "host")]
72impl NnsInventoryListInput for NnsNodeListRequest {
73 fn cache(&self) -> &NnsInventoryCacheRequest {
74 &self.cache
75 }
76
77 fn source_endpoint(&self) -> &str {
78 &self.source_endpoint
79 }
80
81 fn now_unix_secs(&self) -> u64 {
82 self.now_unix_secs
83 }
84}
85
86#[derive(Clone, Debug, Default, Eq, PartialEq)]
93pub struct NnsNodeListFilters {
94 pub subnet: Option<String>,
95 pub subnet_kind: Option<String>,
96 pub data_center: Option<String>,
97 pub node_provider: Option<String>,
98 pub node_operator: Option<String>,
99}
100
101impl NnsNodeListFilters {
102 #[must_use]
103 pub const fn is_empty(&self) -> bool {
104 self.subnet.is_none()
105 && self.subnet_kind.is_none()
106 && self.data_center.is_none()
107 && self.node_provider.is_none()
108 && self.node_operator.is_none()
109 }
110}