use reputation_core::{Calculator, Result, ReputationError, ValidationError};
use reputation_types::AgentData;
use chrono::Utc;
fn main() {
let invalid_agent = AgentData {
did: "invalid-did".to_string(), created_at: Utc::now(),
mcp_level: None,
identity_verified: false,
security_audit_passed: false,
open_source: false,
total_interactions: 0,
total_reviews: 0,
average_rating: None,
positive_reviews: 0,
negative_reviews: 0,
};
let calc = Calculator::default();
match calc.calculate(&invalid_agent) {
Ok(score) => println!("Score: {}", score.score),
Err(ReputationError::ValidationError(ValidationError::InvalidDid(did))) => {
eprintln!("Invalid DID format: {}", did);
eprintln!("DIDs must start with 'did:'");
}
Err(e) => eprintln!("Unexpected error: {}", e),
}
let inconsistent_agent = AgentData {
did: "did:test:123".to_string(),
created_at: Utc::now(),
mcp_level: None,
identity_verified: false,
security_audit_passed: false,
open_source: false,
total_interactions: 100,
total_reviews: 20,
average_rating: Some(4.0),
positive_reviews: 15,
negative_reviews: 10, };
match calc.calculate(&inconsistent_agent) {
Ok(_) => println!("Calculation succeeded"),
Err(ReputationError::InconsistentReviews { positive, negative, total }) => {
eprintln!("Review counts don't add up!");
eprintln!("Positive: {}, Negative: {}, Total: {}", positive, negative, total);
eprintln!("Expected total: {}", positive + negative);
}
Err(e) => eprintln!("Other error: {}", e),
}
match Calculator::new(-1.0, 50.0, 80.0) {
Ok(_) => println!("Calculator created"),
Err(e) => eprintln!("Failed to create calculator: {}", e),
}
fn process_agent(agent: &AgentData) -> Result<String> {
let calc = Calculator::default();
let score = calc.calculate(agent)?; Ok(format!("Agent {} has score: {:.1}", agent.did, score.score))
}
let valid_agent = AgentData {
did: "did:test:valid".to_string(),
created_at: Utc::now() - chrono::Duration::days(1),
mcp_level: Some(2),
identity_verified: true,
security_audit_passed: true,
open_source: true,
total_interactions: 100,
total_reviews: 50,
average_rating: Some(4.5),
positive_reviews: 40,
negative_reviews: 10,
};
match process_agent(&valid_agent) {
Ok(msg) => println!("{}", msg),
Err(e) => eprintln!("Failed to process agent: {}", e),
}
}