Skip to main content

ic_query/sns/report/model/reports/
list.rs

1//! Module: sns::report::model::reports::list
2//!
3//! Responsibility: deployed SNS list and info report DTOs.
4//! Does not own: SNS-W fetching, metadata lookup, sorting, or rendering.
5//! Boundary: preserves raw report fields for text and JSON output writers.
6
7use crate::report::ReportProvenance;
8use crate::sns::report::model::MainnetSnsCanisters;
9use serde::Serialize;
10
11///
12/// SnsListReport
13///
14/// Serializable report for deployed SNS listings.
15///
16
17#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
18pub struct SnsListReport {
19    pub schema_version: u32,
20    pub network: String,
21    pub sns_wasm_canister_id: String,
22    pub fetched_at: String,
23    pub source_endpoint: String,
24    pub fetched_by: String,
25    /// Shared record, flattened in serialized output.
26    #[serde(flatten)]
27    pub provenance: ReportProvenance,
28    /// Whether the view includes SNS instances outside the normal visible lifecycle set.
29    pub all_lifecycles: bool,
30    pub verbose: bool,
31    pub sort: String,
32    /// Number of SNS instances in the complete joined catalog before view filtering.
33    pub catalog_sns_count: usize,
34    /// Number of catalog rows excluded by lifecycle filtering.
35    pub excluded_sns_count: usize,
36    pub sns_count: usize,
37    pub metadata_error_count: usize,
38    /// Number of returned rows carrying a bounded lifecycle query error.
39    pub lifecycle_error_count: usize,
40    pub sns_instances: Vec<SnsListRow>,
41}
42
43///
44/// SnsLifecycleOutcome
45///
46/// Raw Swap lifecycle evidence, including queries not requested for direct lookup.
47///
48
49#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, Serialize)]
50#[serde(tag = "status", rename_all = "snake_case", deny_unknown_fields)]
51pub enum SnsLifecycleOutcome {
52    /// This lookup did not request lifecycle evidence.
53    NotCollected,
54    /// Successful query, preserving every raw discriminant.
55    Value {
56        /// Raw successful Swap discriminant.
57        code: i32,
58    },
59    /// Bounded query failure retained with the SNS identity.
60    Failed {
61        /// Bounded original query failure.
62        error: String,
63    },
64}
65
66impl SnsLifecycleOutcome {
67    /// Return the raw successful lifecycle code.
68    #[must_use]
69    pub const fn value(&self) -> Option<i32> {
70        match self {
71            Self::Value { code } => Some(*code),
72            Self::NotCollected | Self::Failed { .. } => None,
73        }
74    }
75
76    /// Return retained failure evidence.
77    #[must_use]
78    pub fn error(&self) -> Option<&str> {
79        match self {
80            Self::Failed { error } => Some(error),
81            Self::NotCollected | Self::Value { .. } => None,
82        }
83    }
84}
85
86///
87/// SnsListRow
88///
89/// Serializable row for one deployed SNS in a list report.
90///
91
92#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
93pub struct SnsListRow {
94    pub id: usize,
95    pub name: String,
96    /// Complete deployed-SNS canister identity, serialized as the existing flat fields.
97    #[serde(flatten)]
98    pub canisters: MainnetSnsCanisters,
99    pub metadata_error: Option<String>,
100    /// Collected lifecycle value or bounded query failure.
101    pub lifecycle: SnsLifecycleOutcome,
102}
103
104///
105/// SnsInfoReport
106///
107/// Serializable report for one deployed SNS resolved by id or root principal.
108///
109
110#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
111pub struct SnsInfoReport {
112    pub schema_version: u32,
113    pub network: String,
114    pub sns_wasm_canister_id: String,
115    pub fetched_at: String,
116    pub source_endpoint: String,
117    pub fetched_by: String,
118    pub id: usize,
119    pub name: String,
120    pub description: Option<String>,
121    pub url: Option<String>,
122    /// Complete deployed-SNS canister identity, serialized as the existing flat fields.
123    #[serde(flatten)]
124    pub canisters: MainnetSnsCanisters,
125    pub metadata_error: Option<String>,
126}