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 sort: String,
31    /// Number of SNS instances in the complete joined catalog before view filtering.
32    pub catalog_sns_count: usize,
33    /// Number of catalog rows excluded by lifecycle filtering.
34    pub excluded_sns_count: usize,
35    pub sns_count: usize,
36    pub metadata_error_count: usize,
37    /// Number of returned rows carrying a bounded lifecycle query error.
38    pub lifecycle_error_count: usize,
39    pub sns_instances: Vec<SnsListRow>,
40}
41
42///
43/// SnsLifecycleOutcome
44///
45/// Raw Swap lifecycle evidence, including queries not requested for direct lookup.
46///
47
48#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, Serialize)]
49#[serde(tag = "status", rename_all = "snake_case", deny_unknown_fields)]
50pub enum SnsLifecycleOutcome {
51    /// This lookup did not request lifecycle evidence.
52    NotCollected,
53    /// Successful query, preserving every raw discriminant.
54    Value {
55        /// Raw successful Swap discriminant.
56        code: i32,
57    },
58    /// Bounded query failure retained with the SNS identity.
59    Failed {
60        /// Bounded original query failure.
61        error: String,
62    },
63}
64
65impl SnsLifecycleOutcome {
66    /// Return the raw successful lifecycle code.
67    #[must_use]
68    pub const fn value(&self) -> Option<i32> {
69        match self {
70            Self::Value { code } => Some(*code),
71            Self::NotCollected | Self::Failed { .. } => None,
72        }
73    }
74
75    /// Return retained failure evidence.
76    #[must_use]
77    pub fn error(&self) -> Option<&str> {
78        match self {
79            Self::Failed { error } => Some(error),
80            Self::NotCollected | Self::Value { .. } => None,
81        }
82    }
83}
84
85///
86/// SnsListRow
87///
88/// Serializable row for one deployed SNS in a list report.
89///
90
91#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
92pub struct SnsListRow {
93    pub id: usize,
94    pub name: String,
95    /// Complete deployed-SNS canister identity, serialized as the existing flat fields.
96    #[serde(flatten)]
97    pub canisters: MainnetSnsCanisters,
98    pub metadata_error: Option<String>,
99    /// Collected lifecycle value or bounded query failure.
100    pub lifecycle: SnsLifecycleOutcome,
101}
102
103///
104/// SnsInfoReport
105///
106/// Serializable report for one deployed SNS resolved by id or root principal.
107///
108
109#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
110pub struct SnsInfoReport {
111    pub schema_version: u32,
112    pub network: String,
113    pub sns_wasm_canister_id: String,
114    pub fetched_at: String,
115    pub source_endpoint: String,
116    pub fetched_by: String,
117    pub id: usize,
118    pub name: String,
119    pub description: Option<String>,
120    pub url: Option<String>,
121    /// Complete deployed-SNS canister identity, serialized as the existing flat fields.
122    #[serde(flatten)]
123    pub canisters: MainnetSnsCanisters,
124    pub metadata_error: Option<String>,
125}