backbone-support 0.9.0

Customer support: issues tracked against service level agreements, and warranty claims
Documentation
//! Repository trait for Issue aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the Issue aggregate.
//! Implementation is in the infrastructure layer.

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

use crate::domain::entity::{Issue, AgreementStatus, IssuePriority, IssueStatus};

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

impl IssuePaginationParams {
    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 IssuePaginatedResult {
    pub data: Vec<Issue>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct IssueFilter {
    pub customer_id: Option<Uuid>,
    pub subject: Option<String>,
    pub description: Option<String>,
    pub priority: Option<IssuePriority>,
    pub sla_id: Option<Uuid>,
    pub status: Option<IssueStatus>,
    pub agreement_status: Option<AgreementStatus>,
    pub response_breached: Option<bool>,
    pub escalated_project_id: Option<Uuid>,
}

impl IssueFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.customer_id.is_some() || self.subject.is_some() || self.description.is_some() || self.priority.is_some() || self.sla_id.is_some() || self.status.is_some() || self.agreement_status.is_some() || self.response_breached.is_some() || self.escalated_project_id.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List issue with pagination
    async fn list(&self, params: IssuePaginationParams) -> Result<IssuePaginatedResult>;

    /// List issue with pagination and filters
    async fn list_with_filters(&self, params: IssuePaginationParams, filters: IssueFilter) -> Result<IssuePaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted issue entities
    async fn list_deleted(&self, params: IssuePaginationParams) -> Result<IssuePaginatedResult>;

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

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

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

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