use std::collections::HashMap;
use crate::{backend::BackendDirection, errors::SqliteGraphError};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PatternTriple {
pub start_label: Option<String>,
pub edge_type: String,
pub end_label: Option<String>,
pub start_props: HashMap<String, String>,
pub end_props: HashMap<String, String>,
pub direction: BackendDirection,
}
impl PatternTriple {
pub fn new(edge_type: impl Into<String>) -> Self {
Self {
start_label: None,
edge_type: edge_type.into(),
end_label: None,
start_props: HashMap::new(),
end_props: HashMap::new(),
direction: BackendDirection::Outgoing,
}
}
pub fn start_label(mut self, label: impl Into<String>) -> Self {
self.start_label = Some(label.into());
self
}
pub fn end_label(mut self, label: impl Into<String>) -> Self {
self.end_label = Some(label.into());
self
}
pub fn start_property(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.start_props.insert(key.into(), value.into());
self
}
pub fn end_property(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.end_props.insert(key.into(), value.into());
self
}
pub fn direction(mut self, direction: BackendDirection) -> Self {
self.direction = direction;
self
}
pub fn validate(&self) -> Result<(), SqliteGraphError> {
if self.edge_type.trim().is_empty() {
return Err(SqliteGraphError::invalid_input("edge_type is required"));
}
Ok(())
}
}