Skip to main content

ic_query/sns/report/model/requests/
proposals.rs

1//! Module: sns::report::model::requests::proposals
2//!
3//! Responsibility: request DTOs for SNS proposal reports.
4//! Does not own: command option parsing, live proposal fetches, or rendering.
5//! Boundary: carries validated proposal inputs into SNS report builders.
6
7use crate::sns::report::{
8    SnsProposalEligibilityFilter, SnsProposalSortDirection, SnsProposalStatusFilter,
9    SnsProposalTopicFilter, SnsProposalsSort,
10};
11use std::path::PathBuf;
12
13///
14/// SnsProposalRequest
15///
16/// Request accepted by the direct SNS proposal detail report builder.
17///
18
19#[derive(Clone, Debug, Eq, PartialEq)]
20pub struct SnsProposalRequest {
21    pub network: String,
22    pub source_endpoint: String,
23    pub now_unix_secs: u64,
24    pub input: String,
25    pub proposal_id: u64,
26    pub cache_root: Option<PathBuf>,
27    pub verbose: bool,
28    pub show_ballots: bool,
29}
30
31impl SnsProposalRequest {
32    #[must_use]
33    pub fn new(
34        network: impl Into<String>,
35        source_endpoint: impl Into<String>,
36        now_unix_secs: u64,
37        input: impl Into<String>,
38        proposal_id: u64,
39    ) -> Self {
40        Self {
41            network: network.into(),
42            source_endpoint: source_endpoint.into(),
43            now_unix_secs,
44            input: input.into(),
45            proposal_id,
46            cache_root: None,
47            verbose: false,
48            show_ballots: false,
49        }
50    }
51
52    #[must_use]
53    pub fn with_cache_root(mut self, cache_root: impl Into<PathBuf>) -> Self {
54        self.cache_root = Some(cache_root.into());
55        self
56    }
57
58    #[must_use]
59    pub const fn with_verbose(mut self, verbose: bool) -> Self {
60        self.verbose = verbose;
61        self
62    }
63
64    #[must_use]
65    pub const fn with_show_ballots(mut self, show_ballots: bool) -> Self {
66        self.show_ballots = show_ballots;
67        self
68    }
69}
70
71///
72/// SnsProposalsRequest
73///
74/// Request accepted by the bounded SNS proposal listing report builder.
75///
76
77#[derive(Clone, Debug, Eq, PartialEq)]
78pub struct SnsProposalsRequest {
79    pub network: String,
80    pub source_endpoint: String,
81    pub now_unix_secs: u64,
82    pub input: String,
83    pub limit: u32,
84    pub before_proposal_id: Option<u64>,
85    pub status: SnsProposalStatusFilter,
86    pub topic: SnsProposalTopicFilter,
87    pub eligibility: SnsProposalEligibilityFilter,
88    pub proposer_neuron_id: Option<String>,
89    pub query: Option<String>,
90    pub sort: SnsProposalsSort,
91    pub sort_direction: SnsProposalSortDirection,
92    pub cache_root: Option<PathBuf>,
93    pub verbose: bool,
94}
95
96impl SnsProposalsRequest {
97    #[must_use]
98    pub fn new(
99        network: impl Into<String>,
100        source_endpoint: impl Into<String>,
101        now_unix_secs: u64,
102        input: impl Into<String>,
103        limit: u32,
104    ) -> Self {
105        Self {
106            network: network.into(),
107            source_endpoint: source_endpoint.into(),
108            now_unix_secs,
109            input: input.into(),
110            limit,
111            before_proposal_id: None,
112            status: SnsProposalStatusFilter::default(),
113            topic: SnsProposalTopicFilter::default(),
114            eligibility: SnsProposalEligibilityFilter::default(),
115            proposer_neuron_id: None,
116            query: None,
117            sort: SnsProposalsSort::default(),
118            sort_direction: SnsProposalSortDirection::default(),
119            cache_root: None,
120            verbose: false,
121        }
122    }
123
124    #[must_use]
125    pub const fn with_before_proposal_id(mut self, before_proposal_id: u64) -> Self {
126        self.before_proposal_id = Some(before_proposal_id);
127        self
128    }
129
130    #[must_use]
131    pub const fn with_status(mut self, status: SnsProposalStatusFilter) -> Self {
132        self.status = status;
133        self
134    }
135
136    #[must_use]
137    pub const fn with_topic(mut self, topic: SnsProposalTopicFilter) -> Self {
138        self.topic = topic;
139        self
140    }
141
142    #[must_use]
143    pub const fn with_eligibility(mut self, eligibility: SnsProposalEligibilityFilter) -> Self {
144        self.eligibility = eligibility;
145        self
146    }
147
148    #[must_use]
149    pub fn with_proposer_neuron_id(mut self, proposer_neuron_id: impl Into<String>) -> Self {
150        self.proposer_neuron_id = Some(proposer_neuron_id.into());
151        self
152    }
153
154    #[must_use]
155    pub fn with_query(mut self, query: impl Into<String>) -> Self {
156        self.query = Some(query.into());
157        self
158    }
159
160    #[must_use]
161    pub const fn with_sort(mut self, sort: SnsProposalsSort) -> Self {
162        self.sort = sort;
163        self.sort_direction = sort.default_direction();
164        self
165    }
166
167    #[must_use]
168    pub const fn with_sort_direction(mut self, sort_direction: SnsProposalSortDirection) -> Self {
169        self.sort_direction = sort_direction;
170        self
171    }
172
173    #[must_use]
174    pub fn with_cache_root(mut self, cache_root: impl Into<PathBuf>) -> Self {
175        self.cache_root = Some(cache_root.into());
176        self
177    }
178
179    #[must_use]
180    pub const fn with_verbose(mut self, verbose: bool) -> Self {
181        self.verbose = verbose;
182        self
183    }
184}
185
186///
187/// SnsProposalsRefreshRequest
188///
189/// Request accepted by the complete SNS proposal snapshot refresh builder.
190///
191
192#[cfg(feature = "host")]
193#[derive(Clone, Debug, Eq, PartialEq)]
194pub struct SnsProposalsRefreshRequest {
195    pub network: String,
196    pub source_endpoint: String,
197    pub now_unix_secs: u64,
198    pub input: String,
199    pub cache_root: PathBuf,
200    pub page_size: u32,
201    pub max_pages: Option<u32>,
202}
203
204#[cfg(feature = "host")]
205impl SnsProposalsRefreshRequest {
206    #[must_use]
207    pub fn new(
208        cache_root: impl Into<PathBuf>,
209        network: impl Into<String>,
210        source_endpoint: impl Into<String>,
211        now_unix_secs: u64,
212        input: impl Into<String>,
213        page_size: u32,
214    ) -> Self {
215        Self {
216            network: network.into(),
217            source_endpoint: source_endpoint.into(),
218            now_unix_secs,
219            input: input.into(),
220            cache_root: cache_root.into(),
221            page_size,
222            max_pages: None,
223        }
224    }
225
226    #[must_use]
227    pub const fn with_max_pages(mut self, max_pages: Option<u32>) -> Self {
228        self.max_pages = max_pages;
229        self
230    }
231}