use crate::error::Result;
use crate::models::{
AddTagRequest, Asset, AuditAction, AuditEntry, AuthContext, Collection,
CreateAssetRequest, CreateCollectionRequest, CreateRelationRequest, Relation,
UpdateAssetRequest, UpdateCollectionRequest,
};
use async_trait::async_trait;
#[async_trait]
pub trait AssetRepository: Send + Sync {
async fn create(&self, request: CreateAssetRequest, user_id: &str) -> Result<Asset>;
async fn get_by_id(&self, id: &str) -> Result<Asset>;
async fn update(
&self,
id: &str,
request: UpdateAssetRequest,
user_id: &str,
) -> Result<Asset>;
async fn soft_delete(&self, id: &str) -> Result<()>;
async fn list(
&self,
limit: i64,
cursor: Option<&str>,
asset_type_tag: Option<&str>,
sort_by: &str,
order: &str,
) -> Result<(Vec<Asset>, Option<String>)>;
async fn search(
&self,
query: Option<&str>,
tag_filters: Vec<(String, String)>,
limit: i64,
cursor: Option<&str>,
) -> Result<(Vec<Asset>, Option<String>)>;
async fn add_tag(
&self,
asset_id: &str,
request: AddTagRequest,
user_id: &str,
) -> Result<crate::models::Tag>;
async fn remove_tag(&self, asset_id: &str, tag_id: &str) -> Result<()>;
async fn exists(&self, id: &str) -> Result<bool>;
async fn update_auth_context(
&self,
id: &str,
auth_context: &AuthContext,
) -> Result<Asset>;
}
#[async_trait]
pub trait RelationRepository: Send + Sync {
async fn create(
&self,
request: CreateRelationRequest,
user_id: &str,
) -> Result<Relation>;
async fn get_by_id(&self, id: &str) -> Result<Relation>;
async fn delete(&self, id: &str) -> Result<()>;
async fn get_asset_relations(&self, asset_id: &str) -> Result<Vec<Relation>>;
async fn delete_by_asset(&self, asset_id: &str) -> Result<u64>;
async fn traverse_graph(
&self,
start_asset_id: &str,
max_depth: u32,
) -> Result<Vec<(String, u32, Vec<Relation>)>>;
async fn get_descendants(&self, root_id: &str) -> Result<Vec<String>>;
async fn would_create_cycle(&self, from_id: &str, to_id: &str) -> Result<bool>;
}
#[async_trait]
pub trait CollectionRepository: Send + Sync {
async fn create(
&self,
request: CreateCollectionRequest,
user_id: &str,
) -> Result<Collection>;
async fn get_by_id(&self, id: &str) -> Result<Collection>;
async fn update(
&self,
id: &str,
request: UpdateCollectionRequest,
user_id: &str,
) -> Result<Collection>;
async fn delete(&self, id: &str) -> Result<()>;
async fn list(
&self,
limit: i64,
cursor: Option<&str>,
) -> Result<(Vec<Collection>, Option<String>)>;
async fn add_asset(&self, collection_id: &str, asset_id: &str) -> Result<()>;
async fn remove_asset(&self, collection_id: &str, asset_id: &str) -> Result<()>;
async fn remove_asset_from_all(&self, asset_id: &str) -> Result<()>;
}
#[async_trait]
pub trait AuditRepository: Send + Sync {
async fn create(
&self,
entity_type: &str,
entity_id: &str,
action: AuditAction,
changes: serde_json::Value,
user_id: &str,
) -> Result<AuditEntry>;
async fn list(
&self,
entity_type: Option<&str>,
entity_id: Option<&str>,
user_id: Option<&str>,
limit: i64,
cursor: Option<&str>,
) -> Result<(Vec<AuditEntry>, Option<String>)>;
async fn get_entity_history(
&self,
entity_type: &str,
entity_id: &str,
limit: i64,
) -> Result<Vec<AuditEntry>>;
}