use async_trait::async_trait;
use anyhow::Result;
use uuid::Uuid;
use crate::domain::entity::{ProcessingJob, JobStatus, ProcessingJobType};
#[derive(Debug, Clone, Default)]
pub struct ProcessingJobPaginationParams {
pub page: u32,
pub per_page: u32,
}
impl ProcessingJobPaginationParams {
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 ProcessingJobPaginatedResult {
pub data: Vec<ProcessingJob>,
pub total: u64,
pub page: u32,
pub per_page: u32,
}
#[derive(Debug, Clone, Default)]
pub struct ProcessingJobFilter {
pub file_id: Option<Uuid>,
pub job_type: Option<ProcessingJobType>,
pub status: Option<JobStatus>,
pub error_message: Option<String>,
}
impl ProcessingJobFilter {
pub fn has_filters(&self) -> bool {
self.file_id.is_some() || self.job_type.is_some() || self.status.is_some() || self.error_message.is_some()
}
}
#[async_trait]
pub trait ProcessingJobRepository: Send + Sync {
async fn save(&self, entity: &ProcessingJob) -> Result<ProcessingJob>;
async fn find_by_id(&self, id: &str) -> Result<Option<ProcessingJob>>;
async fn find_all(&self) -> Result<Vec<ProcessingJob>>;
async fn update(&self, id: &str, entity: &ProcessingJob) -> Result<Option<ProcessingJob>>;
async fn delete(&self, id: &str) -> Result<bool>;
async fn list(&self, params: ProcessingJobPaginationParams) -> Result<ProcessingJobPaginatedResult>;
async fn list_with_filters(&self, params: ProcessingJobPaginationParams, filters: ProcessingJobFilter) -> Result<ProcessingJobPaginatedResult>;
async fn count(&self) -> Result<u64>;
async fn count_with_filters(&self, filters: ProcessingJobFilter) -> 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<ProcessingJob>>;
async fn list_deleted(&self, params: ProcessingJobPaginationParams) -> Result<ProcessingJobPaginatedResult>;
async fn empty_trash(&self) -> Result<u64>;
async fn bulk_save(&self, entities: &[ProcessingJob]) -> Result<Vec<ProcessingJob>>;
async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}