backbone-catalog 0.7.0

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

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

use crate::domain::entity::UomConversion;

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

impl UomConversionPaginationParams {
    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 UomConversionPaginatedResult {
    pub data: Vec<UomConversion>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

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

impl UomConversionFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.from_uom_id.is_some() || self.to_uom_id.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List uom_conversion with pagination
    async fn list(&self, params: UomConversionPaginationParams) -> Result<UomConversionPaginatedResult>;

    /// List uom_conversion with pagination and filters
    async fn list_with_filters(&self, params: UomConversionPaginationParams, filters: UomConversionFilter) -> Result<UomConversionPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted uom_conversion entities
    async fn list_deleted(&self, params: UomConversionPaginationParams) -> Result<UomConversionPaginatedResult>;

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

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

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

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