use async_trait::async_trait;
use anyhow::Result;
use uuid::Uuid;
use crate::domain::entity::{FileComment, CommentStatus};
#[derive(Debug, Clone, Default)]
pub struct FileCommentPaginationParams {
pub page: u32,
pub per_page: u32,
}
impl FileCommentPaginationParams {
pub fn new(page: u32, per_page: u32) -> Self {
Self { page, per_page }
}
pub fn offset(&self) -> u64 {
((self.page.saturating_sub(1)) * self.per_page) as u64
}
pub fn limit(&self) -> u64 {
self.per_page as u64
}
}
#[derive(Debug, Clone)]
pub struct FileCommentPaginatedResult {
pub data: Vec<FileComment>,
pub total: u64,
pub page: u32,
pub per_page: u32,
}
#[derive(Debug, Clone, Default)]
pub struct FileCommentFilter {
pub file_id: Option<Uuid>,
pub user_id: Option<Uuid>,
pub parent_id: Option<Uuid>,
pub content: Option<String>,
pub resolved: Option<bool>,
pub resolved_by: Option<Uuid>,
pub status: Option<CommentStatus>,
}
impl FileCommentFilter {
pub fn has_filters(&self) -> bool {
self.file_id.is_some() || self.user_id.is_some() || self.parent_id.is_some() || self.content.is_some() || self.resolved.is_some() || self.resolved_by.is_some() || self.status.is_some()
}
}
#[async_trait]
pub trait FileCommentRepository: Send + Sync {
async fn save(&self, entity: &FileComment) -> Result<FileComment>;
async fn find_by_id(&self, id: &str) -> Result<Option<FileComment>>;
async fn find_all(&self) -> Result<Vec<FileComment>>;
async fn update(&self, id: &str, entity: &FileComment) -> Result<Option<FileComment>>;
async fn delete(&self, id: &str) -> Result<bool>;
async fn list(&self, params: FileCommentPaginationParams) -> Result<FileCommentPaginatedResult>;
async fn list_with_filters(&self, params: FileCommentPaginationParams, filters: FileCommentFilter) -> Result<FileCommentPaginatedResult>;
async fn count(&self) -> Result<u64>;
async fn count_with_filters(&self, filters: FileCommentFilter) -> 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<FileComment>>;
async fn list_deleted(&self, params: FileCommentPaginationParams) -> Result<FileCommentPaginatedResult>;
async fn empty_trash(&self) -> Result<u64>;
async fn bulk_save(&self, entities: &[FileComment]) -> Result<Vec<FileComment>>;
async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}