use serde::{Deserialize, Serialize};
#[derive(Debug, thiserror::Error)]
pub enum KgError {
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("API error: {status} - {message}")]
Api { status: u16, message: String },
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Entity {
pub id: String,
#[serde(rename = "type")]
pub entity_type: String,
pub name: String,
#[serde(default)]
pub properties: serde_json::Value,
#[serde(default)]
pub created_at: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Edge {
pub id: String,
pub source: String,
pub target: String,
#[serde(rename = "type")]
pub edge_type: String,
#[serde(default)]
pub weight: Option<f64>,
#[serde(default)]
pub properties: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueryParams {
pub query: String,
#[serde(default = "default_limit")]
pub limit: usize,
#[serde(default)]
pub offset: usize,
#[serde(skip_serializing_if = "Option::is_none")]
pub entity_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub min_weight: Option<f64>,
}
fn default_limit() -> usize {
50
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchResult {
pub entities: Vec<Entity>,
pub edges: Vec<Edge>,
pub total: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateEntityRequest {
#[serde(rename = "type")]
pub entity_type: String,
pub name: String,
#[serde(default)]
pub properties: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateEdgeRequest {
pub source: String,
pub target: String,
#[serde(rename = "type")]
pub edge_type: String,
#[serde(default)]
pub weight: Option<f64>,
#[serde(default)]
pub properties: serde_json::Value,
}