backbone-inventory 0.17.2

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

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

use crate::domain::entity::{PutawayRule, PutawaySublocation};

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

impl PutawayRulePaginationParams {
    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 PutawayRulePaginatedResult {
    pub data: Vec<PutawayRule>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct PutawayRuleFilter {
    pub location_in_id: Option<Uuid>,
    pub location_out_id: Option<Uuid>,
    pub item_id: Option<Uuid>,
    pub category_id: Option<Uuid>,
    pub package_type_id: Option<Uuid>,
    pub storage_category_id: Option<Uuid>,
    pub sublocation: Option<PutawaySublocation>,
    pub active: Option<bool>,
}

impl PutawayRuleFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.location_in_id.is_some() || self.location_out_id.is_some() || self.item_id.is_some() || self.category_id.is_some() || self.package_type_id.is_some() || self.storage_category_id.is_some() || self.sublocation.is_some() || self.active.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List putaway_rule with pagination
    async fn list(&self, params: PutawayRulePaginationParams) -> Result<PutawayRulePaginatedResult>;

    /// List putaway_rule with pagination and filters
    async fn list_with_filters(&self, params: PutawayRulePaginationParams, filters: PutawayRuleFilter) -> Result<PutawayRulePaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted putaway_rule entities
    async fn list_deleted(&self, params: PutawayRulePaginationParams) -> Result<PutawayRulePaginatedResult>;

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

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

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

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