backbone-pos 0.8.0

Point of sale — cashier session, ticket + multi-tender; orchestrates billing (revenue) + payment (settlement), posts no GL directly
Documentation
//! Repository trait for PosPayment aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the PosPayment aggregate.
//! Implementation is in the infrastructure layer.

use async_trait::async_trait;
use anyhow::Result;
use uuid::Uuid;

use crate::domain::entity::{PosPayment, PosPaymentMethod};

/// Pagination parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct PosPaymentPaginationParams {
    pub page: u32,
    pub per_page: u32,
}

impl PosPaymentPaginationParams {
    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
    }
}

/// Paginated result for list queries
#[derive(Debug, Clone)]
pub struct PosPaymentPaginatedResult {
    pub data: Vec<PosPayment>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct PosPaymentFilter {
    pub pos_invoice_id: Option<Uuid>,
    pub payment_method: Option<PosPaymentMethod>,
    pub reference_no: Option<String>,
    pub client_uuid: Option<Uuid>,
    pub payment_entry_id: Option<Uuid>,
}

impl PosPaymentFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.pos_invoice_id.is_some() || self.payment_method.is_some() || self.reference_no.is_some() || self.client_uuid.is_some() || self.payment_entry_id.is_some()
    }
}

/// Repository trait for PosPayment aggregate
///
/// This trait defines the persistence contract for PosPayment entities.
/// Implementations should be in the infrastructure layer.
#[async_trait]
pub trait PosPaymentRepository: Send + Sync {

    // =========================================================================
    // Core CRUD Operations
    // =========================================================================

    /// Save a new pos_payment entity
    async fn save(&self, entity: &PosPayment) -> Result<PosPayment>;

    /// Find pos_payment by ID
    async fn find_by_id(&self, id: &str) -> Result<Option<PosPayment>>;

    /// Find all pos_payment entities
    async fn find_all(&self) -> Result<Vec<PosPayment>>;

    /// Update pos_payment by ID
    async fn update(&self, id: &str, entity: &PosPayment) -> Result<Option<PosPayment>>;

    /// Delete pos_payment by ID
    async fn delete(&self, id: &str) -> Result<bool>;

    // =========================================================================
    // Pagination
    // =========================================================================

    /// List pos_payment with pagination
    async fn list(&self, params: PosPaymentPaginationParams) -> Result<PosPaymentPaginatedResult>;

    /// List pos_payment with pagination and filters
    async fn list_with_filters(&self, params: PosPaymentPaginationParams, filters: PosPaymentFilter) -> Result<PosPaymentPaginatedResult>;

    /// Count all pos_payment entities
    async fn count(&self) -> Result<u64>;

    /// Count pos_payment entities matching filters
    async fn count_with_filters(&self, filters: PosPaymentFilter) -> Result<u64>;

    /// Check if pos_payment exists by ID
    async fn exists(&self, id: &str) -> Result<bool>;

    // =========================================================================
    // Soft Delete Operations
    // =========================================================================

    /// Soft delete pos_payment by ID
    async fn soft_delete(&self, id: &str) -> Result<bool>;

    /// Restore soft-deleted pos_payment by ID
    async fn restore(&self, id: &str) -> Result<Option<PosPayment>>;

    /// List soft-deleted pos_payment entities
    async fn list_deleted(&self, params: PosPaymentPaginationParams) -> Result<PosPaymentPaginatedResult>;

    /// Empty trash (permanently delete all soft-deleted entities)
    async fn empty_trash(&self) -> Result<u64>;

    // =========================================================================
    // Bulk Operations
    // =========================================================================

    /// Bulk save pos_payment entities
    async fn bulk_save(&self, entities: &[PosPayment]) -> Result<Vec<PosPayment>>;

    /// Bulk delete by IDs
    async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}