1use serde::{Deserialize, Serialize};
2
3pub const API_VERSION: &str = "v1";
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6#[serde(rename_all = "snake_case")]
7pub enum Archetype {
8 Web,
9 Tui,
10 Tooling,
11}
12
13impl std::fmt::Display for Archetype {
14 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15 match self {
16 Self::Web => write!(f, "web"),
17 Self::Tui => write!(f, "tui"),
18 Self::Tooling => write!(f, "tooling"),
19 }
20 }
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
24#[serde(rename_all = "snake_case")]
25pub enum TemplateEngineKind {
26 Handlebars,
27 MiniJinja,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
31#[serde(rename_all = "snake_case")]
32pub enum CheckStatus {
33 Passed,
34 Failed,
35 Skipped,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
39pub struct DecisionTrace {
40 pub field: String,
41 pub source: String,
42 pub value: String,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
46pub struct Artifact {
47 pub path: String,
48 pub kind: String,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
52pub struct CheckReport {
53 pub name: String,
54 pub status: String,
55 pub detail: String,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
59pub struct ResolvedConfigReport {
60 pub project_name: String,
61 pub archetype: String,
62 pub template_engine: String,
63 pub profile: String,
64 pub run_post_gen_checks: bool,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
68pub struct JsonEnvelope {
69 pub api_version: String,
70 pub command: String,
71 pub status: String,
72 pub errors: Vec<String>,
73 pub warnings: Vec<String>,
74 pub artifacts: Vec<Artifact>,
75 pub checks: Vec<CheckReport>,
76 pub resolved_config: Option<ResolvedConfigReport>,
77 pub decision_trace: Vec<DecisionTrace>,
78}
79
80impl JsonEnvelope {
81 pub fn ok(command: &str, artifacts: Vec<Artifact>, decision_trace: Vec<DecisionTrace>) -> Self {
82 Self {
83 api_version: API_VERSION.to_string(),
84 command: command.to_string(),
85 status: "ok".to_string(),
86 errors: vec![],
87 warnings: vec![],
88 artifacts,
89 checks: vec![],
90 resolved_config: None,
91 decision_trace,
92 }
93 }
94
95 pub fn error(command: &str, msg: String) -> Self {
96 Self {
97 api_version: API_VERSION.to_string(),
98 command: command.to_string(),
99 status: "error".to_string(),
100 errors: vec![msg],
101 warnings: vec![],
102 artifacts: vec![],
103 checks: vec![],
104 resolved_config: None,
105 decision_trace: vec![],
106 }
107 }
108}