reputation-core 0.1.0

Core calculation engine for the KnowThat Reputation System with advanced scoring algorithms
Documentation
use reputation_core::{Calculator, Result, ReputationError, ValidationError};
use reputation_types::AgentData;
use chrono::Utc;

fn main() {
    // Example 1: Handling validation errors
    let invalid_agent = AgentData {
        did: "invalid-did".to_string(),  // Missing "did:" prefix
        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),
    }

    // Example 2: Handling inconsistent review data
    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,  // 15 + 10 = 25, but total_reviews = 20!
    };

    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),
    }

    // Example 3: Handling builder errors
    match Calculator::new(-1.0, 50.0, 80.0) {
        Ok(_) => println!("Calculator created"),
        Err(e) => eprintln!("Failed to create calculator: {}", e),
    }

    // Example 4: Proper error propagation
    fn process_agent(agent: &AgentData) -> Result<String> {
        let calc = Calculator::default();
        let score = calc.calculate(agent)?;  // ? operator propagates errors
        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),
    }
}