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 Bin aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the Bin aggregate.
//! Implementation is in the infrastructure layer.

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

use crate::domain::entity::Bin;

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

impl BinPaginationParams {
    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 BinPaginatedResult {
    pub data: Vec<Bin>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct BinFilter {
    pub item_id: Option<Uuid>,
    pub warehouse_id: Option<Uuid>,
}

impl BinFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.item_id.is_some() || self.warehouse_id.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List bin with pagination
    async fn list(&self, params: BinPaginationParams) -> Result<BinPaginatedResult>;

    /// List bin with pagination and filters
    async fn list_with_filters(&self, params: BinPaginationParams, filters: BinFilter) -> Result<BinPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted bin entities
    async fn list_deleted(&self, params: BinPaginationParams) -> Result<BinPaginatedResult>;

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

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

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

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