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

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

use crate::domain::entity::{Question, EventQuestionKind};

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

impl QuestionPaginationParams {
    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 QuestionPaginatedResult {
    pub data: Vec<Question>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct QuestionFilter {
    pub question: Option<String>,
    pub question_kind: Option<EventQuestionKind>,
    pub is_default: Option<bool>,
    pub is_reusable: Option<bool>,
    pub once_per_order: Option<bool>,
}

impl QuestionFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.question.is_some() || self.question_kind.is_some() || self.is_default.is_some() || self.is_reusable.is_some() || self.once_per_order.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List question with pagination
    async fn list(&self, params: QuestionPaginationParams) -> Result<QuestionPaginatedResult>;

    /// List question with pagination and filters
    async fn list_with_filters(&self, params: QuestionPaginationParams, filters: QuestionFilter) -> Result<QuestionPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted question entities
    async fn list_deleted(&self, params: QuestionPaginationParams) -> Result<QuestionPaginatedResult>;

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

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

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

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