backbone-mailing 0.6.0

Email marketing — mass-mail engine: audiences, subscriptions, hand-set mailing lifecycle, seeded A/B testing, per-recipient traces, cycle-44 bridge targets (Odoo mass_mailing port)
//! Repository trait for OptOutReason aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the OptOutReason aggregate.
//! Implementation is in the infrastructure layer.

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

use crate::domain::entity::OptOutReason;

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

impl OptOutReasonPaginationParams {
    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 OptOutReasonPaginatedResult {
    pub data: Vec<OptOutReason>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct OptOutReasonFilter {
    pub name: Option<String>,
    pub is_feedback: Option<bool>,
}

impl OptOutReasonFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.name.is_some() || self.is_feedback.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List opt_out_reason with pagination
    async fn list(&self, params: OptOutReasonPaginationParams) -> Result<OptOutReasonPaginatedResult>;

    /// List opt_out_reason with pagination and filters
    async fn list_with_filters(&self, params: OptOutReasonPaginationParams, filters: OptOutReasonFilter) -> Result<OptOutReasonPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted opt_out_reason entities
    async fn list_deleted(&self, params: OptOutReasonPaginationParams) -> Result<OptOutReasonPaginatedResult>;

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

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

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

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