backbone-mail 0.2.32

Odoo mail core port — message/notification/followers/activity/alias/sms queue (schema: messaging)
//! Repository trait for MailNotification aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the MailNotification aggregate.
//! Implementation is in the infrastructure layer.

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

use crate::domain::entity::{MailNotification, MailNotificationStatus, MailNotificationType, NotificationFailureType};

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

impl MailNotificationPaginationParams {
    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 MailNotificationPaginatedResult {
    pub data: Vec<MailNotification>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct MailNotificationFilter {
    pub mail_message_id: Option<Uuid>,
    pub res_partner_id: Option<Uuid>,
    pub notification_type: Option<MailNotificationType>,
    pub notification_status: Option<MailNotificationStatus>,
    pub failure_type: Option<NotificationFailureType>,
    pub failure_reason: Option<String>,
    pub mail_mail_id_int: Option<Uuid>,
    pub is_read: Option<bool>,
}

impl MailNotificationFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.mail_message_id.is_some() || self.res_partner_id.is_some() || self.notification_type.is_some() || self.notification_status.is_some() || self.failure_type.is_some() || self.failure_reason.is_some() || self.mail_mail_id_int.is_some() || self.is_read.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List mail_notification with pagination
    async fn list(&self, params: MailNotificationPaginationParams) -> Result<MailNotificationPaginatedResult>;

    /// List mail_notification with pagination and filters
    async fn list_with_filters(&self, params: MailNotificationPaginationParams, filters: MailNotificationFilter) -> Result<MailNotificationPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted mail_notification entities
    async fn list_deleted(&self, params: MailNotificationPaginationParams) -> Result<MailNotificationPaginatedResult>;

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

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

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

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