use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::path::Path;
pub trait Analyzer: Send + Sync {
type Input;
type Output;
fn analyze(&self, input: Self::Input) -> Result<Self::Output>;
fn name(&self) -> &str;
}
pub trait Scorer: Send + Sync {
type Item;
fn score(&self, item: &Self::Item) -> f64;
fn methodology(&self) -> &str;
}
pub trait FileSystem: Send + Sync {
fn read_file(&self, path: &Path) -> Result<String>;
fn write_file(&self, path: &Path, contents: &str) -> Result<()>;
fn exists(&self, path: &Path) -> bool;
fn glob(&self, pattern: &str) -> Result<Vec<std::path::PathBuf>>;
}
pub trait Parser: Send + Sync {
type Ast;
fn parse(&self, source: &str, path: &Path) -> Result<Self::Ast>;
fn language(&self) -> &str;
}
pub trait ComplexityCalculator: Send + Sync {
type Input;
fn cyclomatic_complexity(&self, input: &Self::Input) -> u32;
fn cognitive_complexity(&self, input: &Self::Input) -> u32;
fn halstead_metrics(&self, input: &Self::Input) -> HalsteadMetrics;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HalsteadMetrics {
pub volume: f64,
pub difficulty: f64,
pub effort: f64,
pub time: f64,
pub bugs: f64,
}
pub trait Formatter: Send + Sync {
type Report;
fn format(&self, report: &Self::Report) -> Result<String>;
fn format_name(&self) -> &str;
}
pub trait ConfigProvider: Send + Sync {
fn get(&self, key: &str) -> Option<String>;
fn set(&mut self, key: String, value: String);
fn load_from_file(&self, path: &Path) -> Result<()>;
}
pub trait Detector: Send + Sync {
type Context;
type Detection;
fn detect(&self, context: &Self::Context) -> Vec<Self::Detection>;
fn confidence(&self) -> f64;
}
pub trait PriorityCalculator: Send + Sync {
type Item;
fn calculate_priority(&self, item: &Self::Item) -> f64;
fn get_factors(&self, item: &Self::Item) -> Vec<PriorityFactor>;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PriorityFactor {
pub name: String,
pub weight: f64,
pub value: f64,
pub description: String,
}
pub trait RefactoringDetector: Send + Sync {
type Context;
type Opportunity;
fn detect_opportunities(&self, context: &Self::Context) -> Vec<Self::Opportunity>;
fn estimate_effort(&self, opportunity: &Self::Opportunity) -> EffortEstimate;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EffortEstimate {
pub hours: f64,
pub complexity: String,
pub risk_level: String,
pub confidence: f64,
}
pub trait TestAnalyzer: Send + Sync {
type TestSuite;
fn analyze_coverage(&self, suite: &Self::TestSuite) -> CoverageReport;
fn detect_test_smells(&self, suite: &Self::TestSuite) -> Vec<TestSmell>;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CoverageReport {
pub line_coverage: f64,
pub branch_coverage: f64,
pub function_coverage: f64,
pub uncovered_lines: Vec<usize>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TestSmell {
pub smell_type: String,
pub location: String,
pub severity: String,
pub suggestion: String,
}
pub trait Repository<T>: Send + Sync {
fn save(&mut self, entity: T) -> Result<()>;
fn find_by_id(&self, id: &str) -> Option<T>;
fn find_all(&self) -> Vec<T>;
fn delete(&mut self, id: &str) -> Result<()>;
}
pub trait EventPublisher: Send + Sync {
type Event;
fn publish(&self, event: Self::Event) -> Result<()>;
}
pub trait EventSubscriber: Send + Sync {
type Event;
fn handle(&mut self, event: Self::Event) -> Result<()>;
}