use serde::{Deserialize, Serialize};
use crate::types::{CollectiveId, ExperienceId, InsightId, Timestamp};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum InsightType {
Pattern,
Synthesis,
Abstraction,
Correlation,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct DerivedInsight {
pub id: InsightId,
pub collective_id: CollectiveId,
pub content: String,
pub embedding: Vec<f32>,
pub source_experience_ids: Vec<ExperienceId>,
pub insight_type: InsightType,
pub confidence: f32,
pub domain: Vec<String>,
pub created_at: Timestamp,
pub updated_at: Timestamp,
}
pub struct NewDerivedInsight {
pub collective_id: CollectiveId,
pub content: String,
pub embedding: Option<Vec<f32>>,
pub source_experience_ids: Vec<ExperienceId>,
pub insight_type: InsightType,
pub confidence: f32,
pub domain: Vec<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_insight_type_postcard_roundtrip() {
let types = [
InsightType::Pattern,
InsightType::Synthesis,
InsightType::Abstraction,
InsightType::Correlation,
];
for it in &types {
let bytes = postcard::to_stdvec(it).unwrap();
let restored: InsightType = postcard::from_bytes(&bytes).unwrap();
assert_eq!(*it, restored);
}
}
#[test]
fn test_derived_insight_postcard_roundtrip() {
let insight = DerivedInsight {
id: InsightId::new(),
collective_id: CollectiveId::new(),
content: "Test insight content".to_string(),
embedding: vec![0.1, 0.2, 0.3],
source_experience_ids: vec![ExperienceId::new(), ExperienceId::new()],
insight_type: InsightType::Pattern,
confidence: 0.85,
domain: vec!["rust".to_string()],
created_at: Timestamp::now(),
updated_at: Timestamp::now(),
};
let bytes = postcard::to_stdvec(&insight).unwrap();
let restored: DerivedInsight = postcard::from_bytes(&bytes).unwrap();
assert_eq!(insight.id, restored.id);
assert_eq!(insight.collective_id, restored.collective_id);
assert_eq!(insight.content, restored.content);
assert_eq!(insight.embedding, restored.embedding);
assert_eq!(
insight.source_experience_ids,
restored.source_experience_ids
);
assert_eq!(insight.insight_type, restored.insight_type);
assert_eq!(insight.confidence, restored.confidence);
assert_eq!(insight.domain, restored.domain);
}
#[test]
fn test_insight_type_copy_and_eq() {
let a = InsightType::Synthesis;
let b = a; assert_eq!(a, b);
}
#[test]
fn test_insight_type_all_variants_distinct() {
assert_ne!(InsightType::Pattern, InsightType::Synthesis);
assert_ne!(InsightType::Synthesis, InsightType::Abstraction);
assert_ne!(InsightType::Abstraction, InsightType::Correlation);
assert_ne!(InsightType::Pattern, InsightType::Correlation);
}
}