use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct EntityId(pub String);
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct PropertyName(pub String);
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct RelationType(pub String);
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct MeasureId(pub String);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Position3D {
pub x: f64,
pub y: f64,
pub z: f64,
}
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct HyperbolicDistance(pub f64);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Vector {
pub dimensions: Vec<f64>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
String(String),
EntityId(EntityId),
Position(Position3D),
Distance(HyperbolicDistance),
Vector(Vector),
List(Vec<Value>),
Map(HashMap<String, Value>),
Timestamp(i64),
Duration(i64),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Entity {
pub id: EntityId,
pub properties: HashMap<PropertyName, Value>,
pub position: Option<Position3D>,
pub embedding: Option<Vector>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Relationship {
pub id: Option<EntityId>,
pub from_entity: EntityId,
pub to_entity: EntityId,
pub rel_type: RelationType,
pub properties: HashMap<PropertyName, Value>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ResultRow {
pub columns: HashMap<String, Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueryResult {
pub rows: Vec<ResultRow>,
pub column_names: Vec<String>,
pub execution_stats: ExecutionStats,
}
impl From<i64> for Value {
fn from(value: i64) -> Self {
Value::Int(value)
}
}
impl From<i32> for Value {
fn from(value: i32) -> Self {
Value::Int(value as i64)
}
}
impl From<f64> for Value {
fn from(value: f64) -> Self {
Value::Float(value)
}
}
impl From<f32> for Value {
fn from(value: f32) -> Self {
Value::Float(value as f64)
}
}
impl From<String> for Value {
fn from(value: String) -> Self {
Value::String(value)
}
}
impl From<&str> for Value {
fn from(value: &str) -> Self {
Value::String(value.to_string())
}
}
impl From<bool> for Value {
fn from(value: bool) -> Self {
Value::Bool(value)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExecutionStats {
pub execution_time_ms: u64,
pub entities_scanned: u64,
pub relationships_traversed: u64,
pub hyperbolic_operations: u64,
pub cascade_propagations: u64,
}