use crate::core::SearchWarning;
use crate::core::SourceCard;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ProviderStatus {
pub id: String,
pub enabled: bool,
pub kind: String,
pub requires_api_key: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ProviderFailure {
pub id: String,
pub error_class: String,
pub message: String,
}
#[derive(Clone, Debug)]
pub struct WebSearchResponse {
pub query: String,
pub mode: &'static str,
pub results: Vec<SourceCard>,
pub providers_queried: Vec<String>,
pub providers_failed: Vec<ProviderFailure>,
pub warnings: Vec<SearchWarning>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn provider_status_serde_roundtrip() {
let status = ProviderStatus {
id: "duckduckgo".to_string(),
enabled: true,
kind: "html_scrape".to_string(),
requires_api_key: false,
};
let json = serde_json::to_string(&status).unwrap();
let parsed: ProviderStatus = serde_json::from_str(&json).unwrap();
assert_eq!(parsed.id, status.id);
assert_eq!(parsed.enabled, status.enabled);
assert_eq!(parsed.kind, status.kind);
assert_eq!(parsed.requires_api_key, status.requires_api_key);
}
#[test]
fn provider_failure_serde_roundtrip() {
let failure = ProviderFailure {
id: "brave".to_string(),
error_class: "timeout".to_string(),
message: "request timed out".to_string(),
};
let json = serde_json::to_string(&failure).unwrap();
let parsed: ProviderFailure = serde_json::from_str(&json).unwrap();
assert_eq!(parsed.id, failure.id);
assert_eq!(parsed.error_class, failure.error_class);
assert_eq!(parsed.message, failure.message);
}
}