Skip to main content

ic_query/nns/
inventory_request.rs

1//! Module: nns::inventory_request
2//!
3//! Responsibility: define shared request contracts for Registry-derived NNS inventory reports.
4//! Does not own: family-specific filters, source calls, cache IO, or report projection.
5//! Boundary: keeps identical cache, list, info, and refresh provenance from drifting by family.
6
7use std::path::PathBuf;
8
9///
10/// NnsInventoryCacheRequest
11///
12/// Shared cache identity for Registry-derived NNS inventory reports.
13///
14
15#[derive(Clone, Debug, Eq, PartialEq)]
16pub struct NnsInventoryCacheRequest {
17    pub cache_root: PathBuf,
18    pub network: String,
19}
20
21impl NnsInventoryCacheRequest {
22    #[must_use]
23    pub fn new(cache_root: impl Into<PathBuf>, network: impl Into<String>) -> Self {
24        Self {
25            cache_root: cache_root.into(),
26            network: network.into(),
27        }
28    }
29}
30
31///
32/// NnsInventoryListRequest
33///
34/// Shared request for a complete Registry-derived NNS inventory report.
35///
36
37#[derive(Clone, Debug, Eq, PartialEq)]
38pub struct NnsInventoryListRequest {
39    pub cache: NnsInventoryCacheRequest,
40    pub source_endpoint: String,
41    pub now_unix_secs: u64,
42}
43
44impl NnsInventoryListRequest {
45    #[must_use]
46    pub fn new(
47        cache: NnsInventoryCacheRequest,
48        source_endpoint: impl Into<String>,
49        now_unix_secs: u64,
50    ) -> Self {
51        Self {
52            cache,
53            source_endpoint: source_endpoint.into(),
54            now_unix_secs,
55        }
56    }
57}
58
59///
60/// NnsInventoryInfoRequest
61///
62/// Shared request for one Registry-derived NNS inventory row selected by id or prefix.
63///
64
65#[derive(Clone, Debug, Eq, PartialEq)]
66pub struct NnsInventoryInfoRequest {
67    pub cache: NnsInventoryCacheRequest,
68    pub source_endpoint: String,
69    pub input: String,
70    pub now_unix_secs: u64,
71}
72
73impl NnsInventoryInfoRequest {
74    #[cfg(feature = "nns-host")]
75    pub(in crate::nns) fn to_list_request(&self) -> NnsInventoryListRequest {
76        NnsInventoryListRequest {
77            cache: self.cache.clone(),
78            source_endpoint: self.source_endpoint.clone(),
79            now_unix_secs: self.now_unix_secs,
80        }
81    }
82
83    #[must_use]
84    pub fn new(
85        cache: NnsInventoryCacheRequest,
86        source_endpoint: impl Into<String>,
87        input: impl Into<String>,
88        now_unix_secs: u64,
89    ) -> Self {
90        Self {
91            cache,
92            source_endpoint: source_endpoint.into(),
93            input: input.into(),
94            now_unix_secs,
95        }
96    }
97}
98
99///
100/// NnsInventoryRefreshRequest
101///
102/// Shared host request for refreshing one Registry-derived NNS inventory cache.
103///
104
105#[cfg(feature = "nns-host")]
106#[derive(Clone, Debug, Eq, PartialEq)]
107pub struct NnsInventoryRefreshRequest {
108    pub cache: NnsInventoryCacheRequest,
109    pub source_endpoint: String,
110    pub now_unix_secs: u64,
111
112    pub dry_run: bool,
113    pub output_path: Option<PathBuf>,
114}
115
116#[cfg(feature = "nns-host")]
117impl NnsInventoryRefreshRequest {
118    #[must_use]
119    pub fn new(
120        cache: NnsInventoryCacheRequest,
121        source_endpoint: impl Into<String>,
122        now_unix_secs: u64,
123    ) -> Self {
124        Self {
125            cache,
126            source_endpoint: source_endpoint.into(),
127            now_unix_secs,
128
129            dry_run: false,
130            output_path: None,
131        }
132    }
133
134    #[must_use]
135    pub const fn with_dry_run(mut self, dry_run: bool) -> Self {
136        self.dry_run = dry_run;
137        self
138    }
139
140    #[must_use]
141    pub fn with_output_path(mut self, output_path: impl Into<PathBuf>) -> Self {
142        self.output_path = Some(output_path.into());
143        self
144    }
145}