backbone-inventory 0.9.29

Inventory: stock ledger of record (SLE) + moving-average valuation; emits COGS/asset AccountingPost (Delivery/Receipt -> GL)
Documentation
//! Repository trait for Quant aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the Quant aggregate.
//! Implementation is in the infrastructure layer.

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

use crate::domain::entity::Quant;

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

impl QuantPaginationParams {
    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 QuantPaginatedResult {
    pub data: Vec<Quant>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct QuantFilter {
    pub item_id: Option<Uuid>,
    pub location_id: Option<Uuid>,
    pub lot_id: Option<Uuid>,
    pub package_id: Option<Uuid>,
    pub owner_id: Option<Uuid>,
    pub inventory_quantity_set: Option<bool>,
    pub sn_duplicated: Option<bool>,
}

impl QuantFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.item_id.is_some() || self.location_id.is_some() || self.lot_id.is_some() || self.package_id.is_some() || self.owner_id.is_some() || self.inventory_quantity_set.is_some() || self.sn_duplicated.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List quant with pagination
    async fn list(&self, params: QuantPaginationParams) -> Result<QuantPaginatedResult>;

    /// List quant with pagination and filters
    async fn list_with_filters(&self, params: QuantPaginationParams, filters: QuantFilter) -> Result<QuantPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted quant entities
    async fn list_deleted(&self, params: QuantPaginationParams) -> Result<QuantPaginatedResult>;

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

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

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

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