use async_trait::async_trait;
use anyhow::Result;
use uuid::Uuid;
use crate::domain::entity::{PayrollEntry, PayrollStatus};
#[derive(Debug, Clone, Default)]
pub struct PayrollEntryPaginationParams {
pub page: u32,
pub per_page: u32,
}
impl PayrollEntryPaginationParams {
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 PayrollEntryPaginatedResult {
pub data: Vec<PayrollEntry>,
pub total: u64,
pub page: u32,
pub per_page: u32,
}
#[derive(Debug, Clone, Default)]
pub struct PayrollEntryFilter {
pub timesheet_approval_id: Option<Uuid>,
pub status: Option<PayrollStatus>,
pub salary_expense_account_id: Option<Uuid>,
pub salary_payable_account_id: Option<Uuid>,
pub journal_id: Option<Uuid>,
pub accounting_post_id: Option<Uuid>,
}
impl PayrollEntryFilter {
pub fn has_filters(&self) -> bool {
self.timesheet_approval_id.is_some() || self.status.is_some() || self.salary_expense_account_id.is_some() || self.salary_payable_account_id.is_some() || self.journal_id.is_some() || self.accounting_post_id.is_some()
}
}
#[async_trait]
pub trait PayrollEntryRepository: Send + Sync {
async fn save(&self, entity: &PayrollEntry) -> Result<PayrollEntry>;
async fn find_by_id(&self, id: &str) -> Result<Option<PayrollEntry>>;
async fn find_all(&self) -> Result<Vec<PayrollEntry>>;
async fn update(&self, id: &str, entity: &PayrollEntry) -> Result<Option<PayrollEntry>>;
async fn delete(&self, id: &str) -> Result<bool>;
async fn list(&self, params: PayrollEntryPaginationParams) -> Result<PayrollEntryPaginatedResult>;
async fn list_with_filters(&self, params: PayrollEntryPaginationParams, filters: PayrollEntryFilter) -> Result<PayrollEntryPaginatedResult>;
async fn count(&self) -> Result<u64>;
async fn count_with_filters(&self, filters: PayrollEntryFilter) -> 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<PayrollEntry>>;
async fn list_deleted(&self, params: PayrollEntryPaginationParams) -> Result<PayrollEntryPaginatedResult>;
async fn empty_trash(&self) -> Result<u64>;
async fn bulk_save(&self, entities: &[PayrollEntry]) -> Result<Vec<PayrollEntry>>;
async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}