1use std::collections::BTreeMap;
4
5use serde::Serialize;
6use serde_json::Value;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
10pub enum InstallOrigin {
11 #[serde(rename = "registry-prebuilt")]
13 RegistryPrebuilt,
14 #[serde(rename = "registry-source")]
16 RegistrySource,
17 #[serde(rename = "local-archive")]
19 LocalArchive,
20 #[serde(rename = "local-package")]
22 LocalPackage,
23 #[serde(rename = "url")]
25 RemoteUrl,
26 #[serde(rename = "unknown")]
28 Unknown
29}
30
31impl InstallOrigin {
32 #[must_use]
34 pub const fn as_str(self) -> &'static str {
35 match self {
36 Self::RegistryPrebuilt => "registry-prebuilt",
37 Self::RegistrySource => "registry-source",
38 Self::LocalArchive => "local-archive",
39 Self::LocalPackage => "local-package",
40 Self::RemoteUrl => "url",
41 Self::Unknown => "unknown"
42 }
43 }
44}
45
46#[derive(Debug, Clone, Serialize)]
48pub struct TransactionSummary {
49 pub command: String,
51 pub success: usize,
53 pub failed: usize,
55 pub skipped: usize
57}
58
59#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
61pub struct PreflightRow {
62 pub key: String,
64 pub value: String
66}
67
68#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
70pub struct PreflightSummary {
71 pub title: String,
73 pub rows: Vec<PreflightRow>
75}
76
77impl PreflightSummary {
78 pub fn new(title: impl Into<String>) -> Self {
80 Self {
81 title: title.into(),
82 rows: Vec::new()
83 }
84 }
85
86 #[must_use]
88 pub fn row(
89 mut self,
90 key: impl Into<String>,
91 value: impl Into<String>
92 ) -> Self {
93 self.rows.push(PreflightRow {
94 key: key.into(),
95 value: value.into()
96 });
97 self
98 }
99}
100
101#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
103pub struct ExplainItem {
104 pub subject: String,
106 pub reason: String,
108 #[serde(skip_serializing_if = "Vec::is_empty")]
110 pub details: Vec<String>
111}
112
113#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
115pub struct ExplainReport {
116 pub title: String,
118 pub items: Vec<ExplainItem>
120}
121
122impl ExplainReport {
123 pub fn new(title: impl Into<String>) -> Self {
125 Self {
126 title: title.into(),
127 items: Vec::new()
128 }
129 }
130
131 #[must_use]
133 pub fn item(
134 mut self,
135 subject: impl Into<String>,
136 reason: impl Into<String>,
137 details: Vec<String>
138 ) -> Self {
139 self.items.push(ExplainItem {
140 subject: subject.into(),
141 reason: reason.into(),
142 details
143 });
144 self
145 }
146}
147
148#[derive(Debug, Clone, Serialize, PartialEq)]
150pub struct PlanJsonV1 {
151 pub schema: String,
153 pub command: String,
155 #[serde(flatten)]
157 pub fields: BTreeMap<String, Value>
158}
159
160impl PlanJsonV1 {
161 pub fn new(
163 command: impl Into<String>,
164 fields: BTreeMap<String, Value>
165 ) -> Self {
166 Self {
167 schema: "zoi.plan.v1".to_string(),
168 command: command.into(),
169 fields
170 }
171 }
172}