1use uuid::Uuid;
4
5#[derive(Debug, Clone, PartialEq)]
7pub struct Edge {
8 pub source: Uuid,
10 pub edge_type: String,
12 pub target: Uuid,
14 pub is_active: bool,
16 pub weight: f32,
18 pub created_at: u64,
20 pub deleted_at: u64,
22}
23
24impl Edge {
25 pub fn new(
27 source: Uuid,
28 edge_type: impl Into<String>,
29 target: Uuid,
30 is_active: bool,
31 weight: f32,
32 ) -> Self {
33 Self {
34 source,
35 edge_type: edge_type.into(),
36 target,
37 is_active,
38 weight,
39 created_at: current_timestamp_nanos(),
40 deleted_at: 0,
41 }
42 }
43
44 pub fn with_timestamps(
46 source: Uuid,
47 edge_type: impl Into<String>,
48 target: Uuid,
49 is_active: bool,
50 weight: f32,
51 created_at: u64,
52 deleted_at: u64,
53 ) -> Self {
54 Self {
55 source,
56 edge_type: edge_type.into(),
57 target,
58 is_active,
59 weight,
60 created_at,
61 deleted_at,
62 }
63 }
64
65 pub fn is_active_at(&self, timestamp: u64) -> bool {
67 self.created_at <= timestamp && (self.deleted_at == 0 || self.deleted_at > timestamp)
68 }
69}
70
71pub fn current_timestamp_nanos() -> u64 {
73 std::time::SystemTime::now()
74 .duration_since(std::time::UNIX_EPOCH)
75 .expect("System time before Unix epoch")
76 .as_nanos() as u64
77}