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