backbone-integrations 0.6.0

Integration registry: connectors, integration accounts and an idempotent inbound event lane, with one OAuth flow (HMAC-bound state, PKCE)
Documentation
//! Repository trait for IntegrationEvent aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the IntegrationEvent aggregate.
//! Implementation is in the infrastructure layer.

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

use crate::domain::entity::{IntegrationEvent, IntegrationStatus};

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

impl IntegrationEventPaginationParams {
    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 IntegrationEventPaginatedResult {
    pub data: Vec<IntegrationEvent>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct IntegrationEventFilter {
    pub connector_id: Option<Uuid>,
    pub event_type: Option<String>,
    pub external_id: Option<String>,
    pub business_key: Option<String>,
    pub status: Option<IntegrationStatus>,
    pub payload: Option<String>,
    pub mapped_ref_type: Option<String>,
    pub mapped_ref_id: Option<Uuid>,
    pub error_detail: Option<String>,
}

impl IntegrationEventFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.connector_id.is_some() || self.event_type.is_some() || self.external_id.is_some() || self.business_key.is_some() || self.status.is_some() || self.payload.is_some() || self.mapped_ref_type.is_some() || self.mapped_ref_id.is_some() || self.error_detail.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List integration_event with pagination
    async fn list(&self, params: IntegrationEventPaginationParams) -> Result<IntegrationEventPaginatedResult>;

    /// List integration_event with pagination and filters
    async fn list_with_filters(&self, params: IntegrationEventPaginationParams, filters: IntegrationEventFilter) -> Result<IntegrationEventPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted integration_event entities
    async fn list_deleted(&self, params: IntegrationEventPaginationParams) -> Result<IntegrationEventPaginatedResult>;

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

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

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

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