backbone-catalog 0.7.0

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

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

use crate::domain::entity::{ItemGroup, CatalogStatus};

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

impl ItemGroupPaginationParams {
    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 ItemGroupPaginatedResult {
    pub data: Vec<ItemGroup>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct ItemGroupFilter {
    pub code: Option<String>,
    pub name: Option<String>,
    pub parent_id: Option<Uuid>,
    pub is_group: Option<bool>,
    pub status: Option<CatalogStatus>,
}

impl ItemGroupFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.code.is_some() || self.name.is_some() || self.parent_id.is_some() || self.is_group.is_some() || self.status.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List item_group with pagination
    async fn list(&self, params: ItemGroupPaginationParams) -> Result<ItemGroupPaginatedResult>;

    /// List item_group with pagination and filters
    async fn list_with_filters(&self, params: ItemGroupPaginationParams, filters: ItemGroupFilter) -> Result<ItemGroupPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted item_group entities
    async fn list_deleted(&self, params: ItemGroupPaginationParams) -> Result<ItemGroupPaginatedResult>;

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

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

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

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