use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use anyhow::Result;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SuggestionRequest {
pub file_path: PathBuf,
pub content: String,
pub diagnostics: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SuggestionResponse {
pub suggestions: Vec<AiSuggestion>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AiSuggestion {
pub title: String,
pub description: String,
pub code_snippet: Option<String>,
pub confidence: u8,
}
pub trait AiProvider {
fn name(&self) -> &str;
fn suggest(&self, request: SuggestionRequest) -> Result<SuggestionResponse>;
}
pub struct LocalPlaceholderProvider;
impl AiProvider for LocalPlaceholderProvider {
fn name(&self) -> &str {
"local-placeholder"
}
fn suggest(&self, request: SuggestionRequest) -> Result<SuggestionResponse> {
let mut suggestions = Vec::new();
for diagnostic in &request.diagnostics {
if diagnostic.contains("require") {
suggestions.push(AiSuggestion {
title: "Convert to ESM Import".to_string(),
description: format!("Detected CommonJS pattern: '{}'. Consider migrating to ESM for better tree-shaking.", diagnostic),
code_snippet: Some("import name from 'source';".to_string()),
confidence: 90,
});
} else if diagnostic.contains("complexity") {
suggestions.push(AiSuggestion {
title: "Refactor Complex Module".to_string(),
description: "This module has been flagged as high complexity. Consider splitting into smaller functional components.".to_string(),
code_snippet: None,
confidence: 70,
});
}
}
if suggestions.is_empty() {
suggestions.push(AiSuggestion {
title: "Optimize Modernization".to_string(),
description: "Review this file for potential TypeScript adoption or modern ES features.".to_string(),
code_snippet: None,
confidence: 50,
});
}
Ok(SuggestionResponse { suggestions })
}
}