backbone-bucket 0.3.1

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! Repository trait for ContentHash aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the ContentHash aggregate.
//! Implementation is in the infrastructure layer.

use async_trait::async_trait;
use anyhow::Result;

use crate::domain::entity::{ContentHash, StorageBackend};

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

impl ContentHashPaginationParams {
    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 ContentHashPaginatedResult {
    pub data: Vec<ContentHash>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct ContentHashFilter {
    pub hash: Option<String>,
    pub size_bytes: Option<i64>,
    pub storage_key: Option<String>,
    pub storage_backend: Option<StorageBackend>,
    pub fingerprint: Option<String>,
}

impl ContentHashFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.hash.is_some() || self.size_bytes.is_some() || self.storage_key.is_some() || self.storage_backend.is_some() || self.fingerprint.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List content_hash with pagination
    async fn list(&self, params: ContentHashPaginationParams) -> Result<ContentHashPaginatedResult>;

    /// List content_hash with pagination and filters
    async fn list_with_filters(&self, params: ContentHashPaginationParams, filters: ContentHashFilter) -> Result<ContentHashPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted content_hash entities
    async fn list_deleted(&self, params: ContentHashPaginationParams) -> Result<ContentHashPaginatedResult>;

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

    // =========================================================================
    // Query by Unique Fields
    // =========================================================================

    /// Find content_hash by hash
    async fn find_by_hash(&self, hash: &str) -> Result<Option<ContentHash>>;

    // =========================================================================
    // Existence Checks by Unique Fields
    // =========================================================================

    /// Check if content_hash exists by hash
    async fn exists_by_hash(&self, hash: &str) -> Result<bool>;

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

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

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