use crate::core::entities::EncodingResult; use crate::core::errors::EncoderError; use super::entities::{Dict, DictEntry}; use super::errors::RepositoryError; /// The number value can be encoded as many word sets, /// but decoded as one number. For partial values, we can use /// u64, but for the whole decoded value that may be very long, /// we need a string. type DecodedValue = String; pub trait SystemDecoder { fn decode(&self, word: &str) -> DecodedValue; } pub trait SystemEncoder { fn initialize(&self) -> Result<(), EncoderError>; fn encode(&self, word: &str) -> Result; } #[async_trait::async_trait] pub trait DictRepository: Send + Sync { async fn create_dict(&self, name: &str) -> Result<(), RepositoryError>; /// "Upsert" logic: /// - If entry exists (by text), update metadata. /// - If not, insert new. /// - IDs are handled by the Database. async fn save_entries( &self, dict_name: &str, entries: &[DictEntry], ) -> Result<(), RepositoryError>; /// Fetch a page of entries. async fn fetch_many( &self, name: &str, limit: Option, offset: Option, ) -> Result; } pub trait DictSource { fn next_entry(&mut self) -> Option>; }