use std::collections::BTreeMap;
use serde::Serialize;
use serde_json::Value;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
pub enum InstallOrigin {
#[serde(rename = "registry-prebuilt")]
RegistryPrebuilt,
#[serde(rename = "registry-source")]
RegistrySource,
#[serde(rename = "local-archive")]
LocalArchive,
#[serde(rename = "local-package")]
LocalPackage,
#[serde(rename = "url")]
RemoteUrl,
#[serde(rename = "unknown")]
Unknown
}
impl InstallOrigin {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::RegistryPrebuilt => "registry-prebuilt",
Self::RegistrySource => "registry-source",
Self::LocalArchive => "local-archive",
Self::LocalPackage => "local-package",
Self::RemoteUrl => "url",
Self::Unknown => "unknown"
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct TransactionSummary {
pub command: String,
pub success: usize,
pub failed: usize,
pub skipped: usize
}
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
pub struct PreflightRow {
pub key: String,
pub value: String
}
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
pub struct PreflightSummary {
pub title: String,
pub rows: Vec<PreflightRow>
}
impl PreflightSummary {
pub fn new(title: impl Into<String>) -> Self {
Self {
title: title.into(),
rows: Vec::new()
}
}
#[must_use]
pub fn row(
mut self,
key: impl Into<String>,
value: impl Into<String>
) -> Self {
self.rows.push(PreflightRow {
key: key.into(),
value: value.into()
});
self
}
}
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
pub struct ExplainItem {
pub subject: String,
pub reason: String,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub details: Vec<String>
}
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
pub struct ExplainReport {
pub title: String,
pub items: Vec<ExplainItem>
}
impl ExplainReport {
pub fn new(title: impl Into<String>) -> Self {
Self {
title: title.into(),
items: Vec::new()
}
}
#[must_use]
pub fn item(
mut self,
subject: impl Into<String>,
reason: impl Into<String>,
details: Vec<String>
) -> Self {
self.items.push(ExplainItem {
subject: subject.into(),
reason: reason.into(),
details
});
self
}
}
#[derive(Debug, Clone, Serialize, PartialEq)]
pub struct PlanJsonV1 {
pub schema: String,
pub command: String,
#[serde(flatten)]
pub fields: BTreeMap<String, Value>
}
impl PlanJsonV1 {
pub fn new(
command: impl Into<String>,
fields: BTreeMap<String, Value>
) -> Self {
Self {
schema: "zoi.plan.v1".to_string(),
command: command.into(),
fields
}
}
}