backbone-events 0.5.1

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 Event aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the Event aggregate.
//! Implementation is in the infrastructure layer.

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

use crate::domain::entity::{Event, EventBadgeFormat, EventKanbanState};

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

impl EventPaginationParams {
    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 EventPaginatedResult {
    pub data: Vec<Event>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct EventFilter {
    pub name: Option<String>,
    pub event_type_id: Option<Uuid>,
    pub stage_id: Option<Uuid>,
    pub kanban_state: Option<EventKanbanState>,
    pub date_tz: Option<String>,
    pub is_multi_slots: Option<bool>,
    pub seats_limited: Option<bool>,
    pub address_id: Option<Uuid>,
    pub organizer_id: Option<Uuid>,
    pub user_id: Option<Uuid>,
    pub badge_format: Option<EventBadgeFormat>,
    pub is_published: Option<bool>,
}

impl EventFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.name.is_some() || self.event_type_id.is_some() || self.stage_id.is_some() || self.kanban_state.is_some() || self.date_tz.is_some() || self.is_multi_slots.is_some() || self.seats_limited.is_some() || self.address_id.is_some() || self.organizer_id.is_some() || self.user_id.is_some() || self.badge_format.is_some() || self.is_published.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List event with pagination
    async fn list(&self, params: EventPaginationParams) -> Result<EventPaginatedResult>;

    /// List event with pagination and filters
    async fn list_with_filters(&self, params: EventPaginationParams, filters: EventFilter) -> Result<EventPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted event entities
    async fn list_deleted(&self, params: EventPaginationParams) -> Result<EventPaginatedResult>;

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

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

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

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