verifex 0.2.0

Official Rust SDK for the Verifex sanctions screening API
Documentation
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Request to screen a single entity.
#[derive(Debug, Clone, Default, Serialize)]
pub struct ScreenRequest {
    /// Name to screen (required).
    pub name: String,
    /// Entity type filter: `"person"` or `"entity"`.
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub type_: Option<String>,
    /// Country filter (ISO code or full name).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country: Option<String>,
    /// Date of birth filter (e.g. `"1952-10-07"`).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub date_of_birth: Option<String>,
    /// Search mode: `"exact"` or `"broad"` (default).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mode: Option<String>,
}

/// Result of screening a single entity.
#[derive(Debug, Clone, Deserialize)]
pub struct ScreenResult {
    /// The original query.
    pub query: serde_json::Value,
    /// Matching sanctions entries.
    pub matches: Vec<Match>,
    /// Total number of matches found.
    pub total_matches: u32,
    /// Overall risk level: `"clear"`, `"low"`, `"medium"`, `"high"`, `"critical"`.
    pub risk_level: String,
    /// ISO 8601 timestamp.
    pub screened_at: String,
    /// Unique request identifier.
    pub request_id: String,
    /// Sanctions lists that were checked.
    #[serde(default)]
    pub lists_checked: Vec<String>,
    /// API version.
    #[serde(default)]
    pub api_version: String,
}

impl ScreenResult {
    /// Returns `true` if no sanctions matches were found.
    pub fn is_clear(&self) -> bool {
        self.risk_level == "clear"
    }

    /// Returns `true` if at least one match was found.
    pub fn is_match(&self) -> bool {
        self.total_matches > 0
    }

    /// Returns the highest confidence score among matches, or 0.
    pub fn highest_confidence(&self) -> u8 {
        self.matches.iter().map(|m| m.confidence).max().unwrap_or(0)
    }
}

/// A single sanctions list match.
#[derive(Debug, Clone, Deserialize)]
pub struct Match {
    /// Unique entry ID.
    pub id: String,
    /// Primary name from the sanctions list.
    pub name: String,
    /// Known aliases.
    #[serde(default)]
    pub aliases: Vec<String>,
    /// Source list (e.g. `"OFAC"`, `"EU"`, `"UN"`).
    pub source: String,
    /// Entity type (`"person"` or `"entity"`).
    pub entity_type: String,
    /// Nationality/country.
    pub nationality: Option<String>,
    /// Date of birth.
    pub date_of_birth: Option<String>,
    /// Reason/remarks for listing.
    pub reason: Option<String>,
    /// Match confidence score (0-100).
    pub confidence: u8,
    /// Risk level based on confidence.
    pub risk_level: String,
    /// Algorithm that produced this match.
    pub match_type: String,
}

/// Result of batch screening.
#[derive(Debug, Clone, Deserialize)]
pub struct BatchScreenResult {
    /// Individual results for each entity.
    pub results: Vec<ScreenResult>,
    /// Total processing time in milliseconds.
    #[serde(default)]
    pub total_duration_ms: u64,
}

/// API usage statistics.
#[derive(Debug, Clone, Deserialize)]
pub struct UsageStats {
    /// Current plan name.
    pub plan: String,
    /// Monthly screening quota.
    pub monthly_quota: u64,
    /// Screens used this month.
    pub current_month_usage: u64,
    /// Remaining screens this month.
    pub remaining: u64,
    /// Daily usage breakdown.
    #[serde(default)]
    pub daily_breakdown: Vec<DailyUsage>,
    /// Current billing period.
    #[serde(default)]
    pub period: HashMap<String, String>,
}

/// Usage for a single day.
#[derive(Debug, Clone, Deserialize)]
pub struct DailyUsage {
    pub date: String,
    pub count: u64,
}

/// API key metadata.
#[derive(Debug, Clone, Deserialize)]
pub struct ApiKeyInfo {
    pub id: String,
    pub name: String,
    pub prefix: String,
    pub is_active: bool,
    pub created_at: String,
    pub last_used_at: Option<String>,
    pub usage_count: u64,
}

/// Returned when a new API key is created.
#[derive(Debug, Clone, Deserialize)]
pub struct ApiKeyCreated {
    /// The full API key (shown only once).
    pub key: String,
    /// Key prefix for identification.
    pub prefix: String,
    /// Key label.
    pub name: String,
}

/// API health status.
#[derive(Debug, Clone, Deserialize)]
pub struct HealthResponse {
    /// Overall status: `"ok"`, `"degraded"`, or `"down"`.
    pub status: String,
    /// API version.
    pub version: String,
    /// Server uptime in seconds.
    pub uptime: u64,
    /// Database connection status.
    pub database: String,
    /// Redis connection status.
    pub redis: String,
    /// Per-source sanctions list statistics.
    #[serde(default)]
    pub lists: HashMap<String, ListInfo>,
}

impl HealthResponse {
    /// Returns `true` if the API is fully operational.
    pub fn is_healthy(&self) -> bool {
        self.status == "ok"
    }

    /// Returns the total number of entities across all lists.
    pub fn total_entities(&self) -> usize {
        self.lists.values().map(|l| l.count as usize).sum()
    }
}

/// Per-source list metadata.
#[derive(Debug, Clone, Deserialize)]
pub struct ListInfo {
    /// Number of active entities.
    pub count: u64,
    /// Last sync timestamp (ISO 8601).
    pub last_synced: Option<String>,
}