use chrono::{DateTime, Utc};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)]
pub enum UpdateType {
QuestionAnswered,
ProblemSolved,
CodeChanged,
DecisionMade,
ConceptDefined,
RequirementAdded,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct TypedEntity {
pub name: String,
pub entity_type: EntityType,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ContextUpdate {
pub id: Uuid,
pub timestamp: DateTime<Utc>,
pub update_type: UpdateType,
pub content: UpdateContent,
pub related_code: Option<CodeReference>,
pub parent_update: Option<Uuid>,
pub user_marked_important: bool,
pub creates_entities: Vec<String>,
pub creates_relationships: Vec<EntityRelationship>,
pub references_entities: Vec<String>,
#[serde(default)]
pub typed_entities: Vec<TypedEntity>,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct UpdateContent {
pub title: String,
pub description: String,
pub details: Vec<String>,
pub examples: Vec<String>,
pub implications: Vec<String>,
}
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
pub struct CodeReference {
pub file_path: String,
pub start_line: u32,
pub end_line: u32,
pub code_snippet: String,
pub commit_hash: Option<String>,
pub branch: Option<String>,
pub change_description: String,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct EntityRelationship {
pub from_entity: String,
pub to_entity: String,
pub relation_type: RelationType,
pub context: String,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum RelationType {
RequiredBy,
LeadsTo,
RelatedTo,
ConflictsWith,
DependsOn,
Implements,
CausedBy,
Solves,
}
impl std::str::FromStr for RelationType {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"RequiredBy" => Ok(RelationType::RequiredBy),
"LeadsTo" => Ok(RelationType::LeadsTo),
"RelatedTo" => Ok(RelationType::RelatedTo),
"ConflictsWith" => Ok(RelationType::ConflictsWith),
"DependsOn" => Ok(RelationType::DependsOn),
"Implements" => Ok(RelationType::Implements),
"CausedBy" => Ok(RelationType::CausedBy),
"Solves" => Ok(RelationType::Solves),
_ => Err(format!("Unknown RelationType: {}", s)),
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)]
pub enum EntityType {
Technology,
Concept,
Problem,
Solution,
Decision,
CodeComponent,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct EntityData {
pub name: String,
pub entity_type: EntityType,
pub first_mentioned: DateTime<Utc>,
pub last_mentioned: DateTime<Utc>,
pub mention_count: u32,
pub importance_score: f32,
pub description: Option<String>,
}