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