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

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

use crate::domain::entity::DeliveryNoteItem;

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

impl DeliveryNoteItemPaginationParams {
    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 DeliveryNoteItemPaginatedResult {
    pub data: Vec<DeliveryNoteItem>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

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

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

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

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

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

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

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

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

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

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

    /// List delivery_note_item with pagination
    async fn list(&self, params: DeliveryNoteItemPaginationParams) -> Result<DeliveryNoteItemPaginatedResult>;

    /// List delivery_note_item with pagination and filters
    async fn list_with_filters(&self, params: DeliveryNoteItemPaginationParams, filters: DeliveryNoteItemFilter) -> Result<DeliveryNoteItemPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted delivery_note_item entities
    async fn list_deleted(&self, params: DeliveryNoteItemPaginationParams) -> Result<DeliveryNoteItemPaginatedResult>;

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

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

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

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