backbone-catalog 0.7.0

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

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

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

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

impl AttributeValuePaginationParams {
    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 AttributeValuePaginatedResult {
    pub data: Vec<AttributeValue>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct AttributeValueFilter {
    pub attribute_id: Option<Uuid>,
    pub code: Option<String>,
    pub label: Option<String>,
    pub label_en: Option<String>,
    pub swatch_hex: Option<String>,
    pub icon: Option<String>,
    pub status: Option<CatalogStatus>,
}

impl AttributeValueFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.attribute_id.is_some() || self.code.is_some() || self.label.is_some() || self.label_en.is_some() || self.swatch_hex.is_some() || self.icon.is_some() || self.status.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List attribute_value with pagination
    async fn list(&self, params: AttributeValuePaginationParams) -> Result<AttributeValuePaginatedResult>;

    /// List attribute_value with pagination and filters
    async fn list_with_filters(&self, params: AttributeValuePaginationParams, filters: AttributeValueFilter) -> Result<AttributeValuePaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted attribute_value entities
    async fn list_deleted(&self, params: AttributeValuePaginationParams) -> Result<AttributeValuePaginatedResult>;

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

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

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

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