use async_trait::async_trait;
use anyhow::Result;
use uuid::Uuid;
use crate::domain::entity::{PosClosingEntry, PosClosingStatus};
#[derive(Debug, Clone, Default)]
pub struct PosClosingEntryPaginationParams {
pub page: u32,
pub per_page: u32,
}
impl PosClosingEntryPaginationParams {
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 PosClosingEntryPaginatedResult {
pub data: Vec<PosClosingEntry>,
pub total: u64,
pub page: u32,
pub per_page: u32,
}
#[derive(Debug, Clone, Default)]
pub struct PosClosingEntryFilter {
pub pos_profile_id: Option<Uuid>,
pub opening_entry_id: Option<Uuid>,
pub cashier_party_id: Option<Uuid>,
pub status: Option<PosClosingStatus>,
}
impl PosClosingEntryFilter {
pub fn has_filters(&self) -> bool {
self.pos_profile_id.is_some() || self.opening_entry_id.is_some() || self.cashier_party_id.is_some() || self.status.is_some()
}
}
#[async_trait]
pub trait PosClosingEntryRepository: Send + Sync {
async fn save(&self, entity: &PosClosingEntry) -> Result<PosClosingEntry>;
async fn find_by_id(&self, id: &str) -> Result<Option<PosClosingEntry>>;
async fn find_all(&self) -> Result<Vec<PosClosingEntry>>;
async fn update(&self, id: &str, entity: &PosClosingEntry) -> Result<Option<PosClosingEntry>>;
async fn delete(&self, id: &str) -> Result<bool>;
async fn list(&self, params: PosClosingEntryPaginationParams) -> Result<PosClosingEntryPaginatedResult>;
async fn list_with_filters(&self, params: PosClosingEntryPaginationParams, filters: PosClosingEntryFilter) -> Result<PosClosingEntryPaginatedResult>;
async fn count(&self) -> Result<u64>;
async fn count_with_filters(&self, filters: PosClosingEntryFilter) -> 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<PosClosingEntry>>;
async fn list_deleted(&self, params: PosClosingEntryPaginationParams) -> Result<PosClosingEntryPaginatedResult>;
async fn empty_trash(&self) -> Result<u64>;
async fn bulk_save(&self, entities: &[PosClosingEntry]) -> Result<Vec<PosClosingEntry>>;
async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}