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

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

use crate::domain::entity::{Location, LocationUsage};

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

impl LocationPaginationParams {
    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 LocationPaginatedResult {
    pub data: Vec<Location>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct LocationFilter {
    pub name: Option<String>,
    pub complete_name: Option<String>,
    pub active: Option<bool>,
    pub usage: Option<LocationUsage>,
    pub location_id: Option<Uuid>,
    pub parent_path: Option<String>,
    pub barcode: Option<String>,
    pub warehouse_id: Option<Uuid>,
    pub valuation_account_id: Option<Uuid>,
    pub storage_category_id: Option<Uuid>,
}

impl LocationFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.name.is_some() || self.complete_name.is_some() || self.active.is_some() || self.usage.is_some() || self.location_id.is_some() || self.parent_path.is_some() || self.barcode.is_some() || self.warehouse_id.is_some() || self.valuation_account_id.is_some() || self.storage_category_id.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List location with pagination
    async fn list(&self, params: LocationPaginationParams) -> Result<LocationPaginatedResult>;

    /// List location with pagination and filters
    async fn list_with_filters(&self, params: LocationPaginationParams, filters: LocationFilter) -> Result<LocationPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted location entities
    async fn list_deleted(&self, params: LocationPaginationParams) -> Result<LocationPaginatedResult>;

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

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

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

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