use anyhow::Result;
use async_trait::async_trait;
use crate::domain::entity::{Example, ExampleStatus};
use backbone_core::repository::{DomainPaginationParams, DomainPaginatedResult};
pub type ExamplePaginationParams = DomainPaginationParams;
pub type ExamplePaginatedResult = DomainPaginatedResult<Example>;
#[derive(Debug, Clone, Default)]
pub struct ExampleFilter {
pub name: Option<String>,
pub status: Option<ExampleStatus>,
}
impl ExampleFilter {
pub fn has_filters(&self) -> bool {
self.name.is_some() || self.status.is_some()
}
}
#[async_trait]
pub trait ExampleRepository: Send + Sync {
async fn save(&self, entity: &Example) -> Result<Example>;
async fn find_by_id(&self, id: &str) -> Result<Option<Example>>;
async fn find_all(&self) -> Result<Vec<Example>>;
async fn update(&self, id: &str, entity: &Example) -> Result<Option<Example>>;
async fn delete(&self, id: &str) -> Result<bool>;
async fn list(&self, params: ExamplePaginationParams) -> Result<ExamplePaginatedResult>;
async fn list_with_filters(
&self,
params: ExamplePaginationParams,
filters: ExampleFilter,
) -> Result<ExamplePaginatedResult>;
async fn count(&self) -> Result<u64>;
async fn count_with_filters(&self, filters: ExampleFilter) -> Result<u64>;
async fn exists(&self, id: &str) -> Result<bool>;
async fn soft_delete(&self, id: &str) -> Result<bool>;
async fn restore(&self, id: &str) -> Result<Option<Example>>;
async fn list_deleted(&self, params: ExamplePaginationParams) -> Result<ExamplePaginatedResult>;
async fn empty_trash(&self) -> Result<u64>;
async fn bulk_save(&self, entities: &[Example]) -> Result<Vec<Example>>;
async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}