backbone-catalog 0.7.0

Canonical product/service identity: Item, Item Group, UOM (Indonesia-first)
Documentation
//! Repository trait for Uom aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the Uom aggregate.
//! Implementation is in the infrastructure layer.

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

use crate::domain::entity::{Uom, CatalogStatus, UomType};

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

impl UomPaginationParams {
    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 UomPaginatedResult {
    pub data: Vec<Uom>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct UomFilter {
    pub code: Option<String>,
    pub name: Option<String>,
    pub uom_type: Option<UomType>,
    pub relative_uom_id: Option<Uuid>,
    pub is_protected: Option<bool>,
    pub status: Option<CatalogStatus>,
}

impl UomFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.code.is_some() || self.name.is_some() || self.uom_type.is_some() || self.relative_uom_id.is_some() || self.is_protected.is_some() || self.status.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List uom with pagination
    async fn list(&self, params: UomPaginationParams) -> Result<UomPaginatedResult>;

    /// List uom with pagination and filters
    async fn list_with_filters(&self, params: UomPaginationParams, filters: UomFilter) -> Result<UomPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted uom entities
    async fn list_deleted(&self, params: UomPaginationParams) -> Result<UomPaginatedResult>;

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

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

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

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