use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum RiskCategory {
ApiContract,
AsyncBoundary,
SerdeDrift,
AuthGate,
Concurrency,
Other,
}
impl RiskCategory {
#[must_use]
pub fn label(self) -> &'static str {
match self {
Self::ApiContract => "API Contract Change",
Self::AsyncBoundary => "Async Boundary Change",
Self::SerdeDrift => "Serde Schema Drift",
Self::AuthGate => "Auth / Permission Gate",
Self::Concurrency => "Concurrency / Memory Safety",
Self::Other => "Other",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Severity {
Low,
Medium,
High,
Critical,
}
impl Severity {
#[must_use]
pub fn weight(self) -> f32 {
match self {
Self::Low => 1.0,
Self::Medium => 3.0,
Self::High => 6.0,
Self::Critical => 9.0,
}
}
#[must_use]
pub fn marker(self) -> &'static str {
match self {
Self::Low => "✅",
Self::Medium => "🟡",
Self::High => "⚠️",
Self::Critical => "🚨",
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Finding {
pub category: RiskCategory,
pub severity: Severity,
pub file: String,
pub line: Option<u32>,
pub message: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RiskReport {
pub findings: Vec<Finding>,
pub score: f32,
}
impl RiskReport {
#[must_use]
pub fn findings_for(&self, category: RiskCategory) -> Vec<&Finding> {
self.findings
.iter()
.filter(|f| f.category == category)
.collect()
}
#[must_use]
pub fn max_severity(&self) -> Option<Severity> {
self.findings.iter().map(|f| f.severity).max()
}
}