backbone-integrations 0.5.22

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

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

use crate::domain::entity::{IntegrationAccount, IntegrationAccountStatus, OAuthProvider};

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

impl IntegrationAccountPaginationParams {
    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 IntegrationAccountPaginatedResult {
    pub data: Vec<IntegrationAccount>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct IntegrationAccountFilter {
    pub provider: Option<OAuthProvider>,
    pub account_ref: Option<String>,
    pub status: Option<IntegrationAccountStatus>,
    pub scopes: Option<String>,
    pub pkce_verifier: Option<String>,
}

impl IntegrationAccountFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.provider.is_some() || self.account_ref.is_some() || self.status.is_some() || self.scopes.is_some() || self.pkce_verifier.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List integration_account with pagination
    async fn list(&self, params: IntegrationAccountPaginationParams) -> Result<IntegrationAccountPaginatedResult>;

    /// List integration_account with pagination and filters
    async fn list_with_filters(&self, params: IntegrationAccountPaginationParams, filters: IntegrationAccountFilter) -> Result<IntegrationAccountPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted integration_account entities
    async fn list_deleted(&self, params: IntegrationAccountPaginationParams) -> Result<IntegrationAccountPaginatedResult>;

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

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

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

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