use crate::config::LoreConfig;
use crate::error::LoreError;
use crate::model::entry::{Entry, NewEntry, UpdateEntry};
use crate::model::types::{EntryType, ReflectCriteria, ReflectReport, SimilarEntry};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
const fn default_limit() -> u32 {
20
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchQuery {
pub query: String,
pub entry_type: Option<EntryType>,
#[serde(default = "default_limit")]
pub limit: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Filters {
pub status: Option<String>,
#[serde(default = "default_limit")]
pub limit: u32,
#[serde(default)]
pub offset: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryStats {
pub total: u64,
pub by_type: Vec<(EntryType, u64)>,
pub by_status: Vec<(String, u64)>,
pub last_updated: Option<DateTime<Utc>>,
}
#[cfg_attr(test, mockall::automock)]
pub trait EntryRepository: Send + Sync {
fn store(&self, input: NewEntry) -> Result<Entry, LoreError>;
fn get(&self, id: &str) -> Result<Entry, LoreError>;
fn update(&self, id: &str, update: UpdateEntry) -> Result<Entry, LoreError>;
fn delete(&self, id: &str) -> Result<(), LoreError>;
fn search(&self, query: &SearchQuery) -> Result<Vec<Entry>, LoreError>;
fn recent(&self, limit: u32) -> Result<Vec<Entry>, LoreError>;
fn by_type(&self, entry_type: EntryType, filters: &Filters) -> Result<Vec<Entry>, LoreError>;
fn stats(&self) -> Result<MemoryStats, LoreError>;
fn render_all(&self) -> Result<Vec<Entry>, LoreError>;
fn reflect(
&self,
criteria: &ReflectCriteria,
config: &LoreConfig,
) -> Result<ReflectReport, LoreError>;
fn find_similar(
&self,
title: &str,
body: Option<String>,
entry_type: EntryType,
threshold: f64,
) -> Result<Vec<SimilarEntry>, LoreError>;
}