claude_priority/
models.rs1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum CheckType {
6 Naming,
7 Json,
8 Frontmatter,
9}
10
11#[derive(Debug, Clone)]
12pub struct ValidationResult {
13 pub check_type: CheckType,
14 pub passed: bool,
15 pub errors: Vec<String>,
16 pub warnings: Vec<String>,
17}
18
19impl ValidationResult {
20 pub fn new(check_type: CheckType) -> Self {
21 Self {
22 check_type,
23 passed: true,
24 errors: Vec::new(),
25 warnings: Vec::new(),
26 }
27 }
28
29 pub fn add_error(&mut self, error: String) {
30 self.passed = false;
31 self.errors.push(error);
32 }
33
34 pub fn add_warning(&mut self, warning: String) {
35 self.warnings.push(warning);
36 }
37
38 pub fn error_count(&self) -> usize {
39 self.errors.len()
40 }
41
42 pub fn warning_count(&self) -> usize {
43 self.warnings.len()
44 }
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct MarketplaceJson {
49 pub name: String,
50 pub version: String,
51 pub description: String,
52 pub author: serde_json::Value,
53 #[serde(default)]
54 pub skills: Option<Vec<serde_json::Value>>,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct SkillFrontmatter {
59 pub name: String,
60 pub description: String,
61 #[serde(default)]
62 pub license: Option<String>,
63}
64
65#[derive(Debug)]
66pub struct ValidationSummary {
67 pub total_checks: usize,
68 pub passed_checks: usize,
69 pub failed_checks: usize,
70 pub results: Vec<ValidationResult>,
71}
72
73impl ValidationSummary {
74 pub fn new() -> Self {
75 Self {
76 total_checks: 0,
77 passed_checks: 0,
78 failed_checks: 0,
79 results: Vec::new(),
80 }
81 }
82
83 pub fn add_result(&mut self, result: ValidationResult) {
84 self.total_checks += 1;
85 if result.passed {
86 self.passed_checks += 1;
87 } else {
88 self.failed_checks += 1;
89 }
90 self.results.push(result);
91 }
92
93 pub fn is_success(&self) -> bool {
94 self.failed_checks == 0
95 }
96
97 pub fn all_errors(&self) -> Vec<String> {
98 self.results
99 .iter()
100 .flat_map(|r| r.errors.clone())
101 .collect()
102 }
103}
104
105impl Default for ValidationSummary {
106 fn default() -> Self {
107 Self::new()
108 }
109}
110
111impl fmt::Display for CheckType {
112 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
113 match self {
114 CheckType::Naming => write!(f, "Naming conventions"),
115 CheckType::Json => write!(f, "JSON schema"),
116 CheckType::Frontmatter => write!(f, "Frontmatter format"),
117 }
118 }
119}