1use chrono::{DateTime, Utc};
8use serde::{Deserialize, Serialize};
9
10use crate::author::AuthorStamp;
11use crate::ids::{ProjectId, TenantId};
12
13#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
16#[serde(transparent)]
17pub struct EvidenceId(pub String);
18
19#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
23pub struct Evidence {
24 pub id: EvidenceId,
26 pub tenant_id: TenantId,
28 pub project_id: ProjectId,
30 pub source_uri: String,
33 pub source_type: String,
35 pub source_id: String,
38 pub content: String,
40 #[serde(default, skip_serializing_if = "Option::is_none")]
42 pub char_start: Option<u32>,
43 #[serde(default, skip_serializing_if = "Option::is_none")]
45 pub char_end: Option<u32>,
46 #[serde(default, skip_serializing_if = "Option::is_none")]
48 pub byte_start: Option<u64>,
49 #[serde(default, skip_serializing_if = "Option::is_none")]
51 pub byte_end: Option<u64>,
52 #[serde(default, skip_serializing_if = "Option::is_none")]
54 pub observed_at: Option<DateTime<Utc>>,
55 #[serde(default, skip_serializing_if = "Option::is_none")]
57 pub extracted_at: Option<DateTime<Utc>>,
58 #[serde(default, skip_serializing_if = "Option::is_none")]
60 pub extractor_version: Option<String>,
61 #[serde(default, skip_serializing_if = "Option::is_none")]
63 pub confidence: Option<f32>,
64 #[serde(default, skip_serializing_if = "serde_json::Value::is_null")]
67 pub metadata: serde_json::Value,
68
69 #[serde(default, skip_serializing_if = "Option::is_none")]
72 pub author: Option<AuthorStamp>,
73}
74
75impl Evidence {
76 pub fn quick(
78 id: &str,
79 tenant: TenantId,
80 project: ProjectId,
81 source_type: &str,
82 source_id: &str,
83 content: &str,
84 ) -> Self {
85 Self {
86 id: EvidenceId(id.to_string()),
87 tenant_id: tenant,
88 project_id: project,
89 source_uri: format!("antares://{source_type}/{source_id}"),
90 source_type: source_type.to_string(),
91 source_id: source_id.to_string(),
92 content: content.to_string(),
93 char_start: None,
94 char_end: None,
95 byte_start: None,
96 byte_end: None,
97 observed_at: None,
98 extracted_at: None,
99 extractor_version: None,
100 confidence: None,
101 metadata: serde_json::Value::Null,
102 author: None,
103 }
104 }
105}