backbone-events 0.4.0

Events core + the sale/booth/crm/sms/desk overlay — registrations under one authoritative seat counter, the sale seam (order-minted registrations, forward-only paid heal, SO-cancel mirror cascade), booth bookings with the DB exclusivity wall, closed-vocabulary lead rules through a host sink port, the dual-channel (mail/sms) self-arming scheduler, and the exact-match desk verb (Odoo event port, core + overlay)
//! Repository trait for LeadRulePredicate aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the LeadRulePredicate aggregate.
//! Implementation is in the infrastructure layer.

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

use crate::domain::entity::{LeadRulePredicate, EventLeadPredicateAxis};

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

impl LeadRulePredicatePaginationParams {
    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 LeadRulePredicatePaginatedResult {
    pub data: Vec<LeadRulePredicate>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct LeadRulePredicateFilter {
    pub rule_id: Option<Uuid>,
    pub axis: Option<EventLeadPredicateAxis>,
    pub question_id: Option<Uuid>,
}

impl LeadRulePredicateFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.rule_id.is_some() || self.axis.is_some() || self.question_id.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List lead_rule_predicate with pagination
    async fn list(&self, params: LeadRulePredicatePaginationParams) -> Result<LeadRulePredicatePaginatedResult>;

    /// List lead_rule_predicate with pagination and filters
    async fn list_with_filters(&self, params: LeadRulePredicatePaginationParams, filters: LeadRulePredicateFilter) -> Result<LeadRulePredicatePaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted lead_rule_predicate entities
    async fn list_deleted(&self, params: LeadRulePredicatePaginationParams) -> Result<LeadRulePredicatePaginatedResult>;

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

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

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

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