use crate::config::LinksConfig;
use crate::server::entity_registry::EntityRegistry;
use anyhow::Result;
use async_trait::async_trait;
use std::sync::Arc;
use uuid::Uuid;
#[async_trait]
pub trait EntityFetcher: Send + Sync {
async fn fetch_as_json(&self, entity_id: &Uuid) -> Result<serde_json::Value>;
async fn get_sample_entity(&self) -> Result<serde_json::Value> {
Ok(serde_json::json!({}))
}
async fn list_as_json(
&self,
_limit: Option<i32>,
_offset: Option<i32>,
) -> Result<Vec<serde_json::Value>> {
Ok(vec![])
}
}
#[async_trait]
pub trait EntityCreator: Send + Sync {
async fn create_from_json(&self, entity_data: serde_json::Value) -> Result<serde_json::Value>;
async fn update_from_json(
&self,
_entity_id: &Uuid,
_entity_data: serde_json::Value,
) -> Result<serde_json::Value> {
Err(anyhow::anyhow!(
"Update operation not implemented for this entity type"
))
}
async fn delete(&self, _entity_id: &Uuid) -> Result<()> {
Err(anyhow::anyhow!(
"Delete operation not implemented for this entity type"
))
}
}
pub trait Module: Send + Sync {
fn name(&self) -> &str;
fn version(&self) -> &str {
"1.0.0"
}
fn entity_types(&self) -> Vec<&str>;
fn links_config(&self) -> Result<LinksConfig>;
fn register_entities(&self, registry: &mut EntityRegistry);
fn get_entity_fetcher(&self, entity_type: &str) -> Option<Arc<dyn EntityFetcher>>;
fn get_entity_creator(&self, entity_type: &str) -> Option<Arc<dyn EntityCreator>>;
}