use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Default, Serialize)]
pub struct ScreenRequest {
pub name: String,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
pub type_: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub country: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub date_of_birth: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mode: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ScreenResult {
pub query: serde_json::Value,
pub matches: Vec<Match>,
pub total_matches: u32,
pub risk_level: String,
pub screened_at: String,
pub request_id: String,
#[serde(default)]
pub lists_checked: Vec<String>,
#[serde(default)]
pub api_version: String,
}
impl ScreenResult {
pub fn is_clear(&self) -> bool {
self.risk_level == "clear"
}
pub fn is_match(&self) -> bool {
self.total_matches > 0
}
pub fn highest_confidence(&self) -> u8 {
self.matches.iter().map(|m| m.confidence).max().unwrap_or(0)
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct Match {
pub id: String,
pub name: String,
#[serde(default)]
pub aliases: Vec<String>,
pub source: String,
pub entity_type: String,
pub nationality: Option<String>,
pub date_of_birth: Option<String>,
pub reason: Option<String>,
pub confidence: u8,
pub risk_level: String,
pub match_type: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct BatchScreenResult {
pub results: Vec<ScreenResult>,
#[serde(default)]
pub total_duration_ms: u64,
}
#[derive(Debug, Clone, Deserialize)]
pub struct UsageStats {
pub plan: String,
pub monthly_quota: u64,
pub current_month_usage: u64,
pub remaining: u64,
#[serde(default)]
pub daily_breakdown: Vec<DailyUsage>,
#[serde(default)]
pub period: HashMap<String, String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct DailyUsage {
pub date: String,
pub count: u64,
}
#[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,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ApiKeyCreated {
pub key: String,
pub prefix: String,
pub name: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct HealthResponse {
pub status: String,
pub version: String,
pub uptime: u64,
pub database: String,
pub redis: String,
#[serde(default)]
pub lists: HashMap<String, ListInfo>,
}
impl HealthResponse {
pub fn is_healthy(&self) -> bool {
self.status == "ok"
}
pub fn total_entities(&self) -> usize {
self.lists.values().map(|l| l.count as usize).sum()
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct ListInfo {
pub count: u64,
pub last_synced: Option<String>,
}