backbone-integrations 0.6.1

Integration registry: connectors, integration accounts and an idempotent inbound event lane, with one OAuth flow (HMAC-bound state, PKCE)
Documentation
//! IntegrationEvent DTOs (Data Transfer Objects)
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! DTOs provide a clean separation between domain entities and API
//! representations, with validation and OpenAPI documentation support.

use serde::{Deserialize, Serialize};
use uuid::Uuid;
use chrono::{DateTime, Utc};

#[cfg(feature = "openapi")]
#[cfg(feature = "openapi")]
use utoipa::ToSchema;

#[cfg(feature = "validation")]
use validator::Validate;

use crate::domain::entity::IntegrationEvent;
use crate::domain::entity::AuditMetadata;
use crate::domain::entity::IntegrationStatus;

// =============================================================================
// Create DTO
// =============================================================================

/// Request DTO for creating a new IntegrationEvent
///
/// Used in POST requests to create new entities.
/// Excludes auto-generated fields (id, created_at, updated_at, deleted_at).
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct CreateIntegrationEventDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "connector_id")]
    pub connector_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "event_type")]
    pub event_type: String,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "external_id")]
    pub external_id: String,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "business_key")]
    pub business_key: String,
    pub status: IntegrationStatus,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub payload: String,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "mapped_ref_type")]
    pub mapped_ref_type: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "mapped_ref_id")]
    pub mapped_ref_id: Option<Uuid>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "error_detail")]
    pub error_detail: Option<String>,
}

// =============================================================================
// Update DTO
// =============================================================================

/// Request DTO for full update of a IntegrationEvent
///
/// Used in PUT requests for full entity replacement.
/// All fields are required (except auto-generated ones).
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct UpdateIntegrationEventDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "connector_id")]
    pub connector_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "event_type")]
    pub event_type: String,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "external_id")]
    pub external_id: String,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "business_key")]
    pub business_key: String,
    pub status: IntegrationStatus,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub payload: String,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "mapped_ref_type")]
    pub mapped_ref_type: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "mapped_ref_id")]
    pub mapped_ref_id: Option<Uuid>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "error_detail")]
    pub error_detail: Option<String>,
}

// =============================================================================
// Patch DTO
// =============================================================================

/// Request DTO for partial update of a IntegrationEvent
///
/// Used in PATCH requests for partial updates.
/// All fields are optional - only provided fields will be updated.
#[derive(Debug, Clone, Default, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct PatchIntegrationEventDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "connector_id")]
    pub connector_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "event_type")]
    pub event_type: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "external_id")]
    pub external_id: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "business_key")]
    pub business_key: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<IntegrationStatus>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub payload: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "mapped_ref_type")]
    pub mapped_ref_type: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "mapped_ref_id")]
    pub mapped_ref_id: Option<Uuid>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "error_detail")]
    pub error_detail: Option<String>,
}

impl PatchIntegrationEventDto {
    /// Check if any field is set
    pub fn has_changes(&self) -> bool {
        self.connector_id.is_some() || self.event_type.is_some() || self.external_id.is_some() || self.business_key.is_some() || self.status.is_some() || self.payload.is_some() || self.mapped_ref_type.is_some() || self.mapped_ref_id.is_some() || self.error_detail.is_some()
    }
}

// =============================================================================
// Response DTO
// =============================================================================

/// Response DTO for IntegrationEvent entity
///
/// Used in API responses for single entity.
/// Includes all fields including metadata.
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct IntegrationEventResponseDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub connector_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub event_type: String,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub external_id: String,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub business_key: String,
    pub status: IntegrationStatus,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub payload: String,
    pub mapped_ref_type: Option<String>,
    pub mapped_ref_id: Option<Uuid>,
    pub error_detail: Option<String>,
    pub metadata: AuditMetadata,
}

// =============================================================================
// List Response DTO
// =============================================================================

/// Paginated list response for IntegrationEvent entities
///
/// Used in API responses for list endpoints.
/// Includes pagination metadata.
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct IntegrationEventListResponseDto {
    /// List of items
    pub items: Vec<IntegrationEventResponseDto>,
    /// Total number of items (across all pages)
    pub total: u64,
    /// Current page number (1-indexed)
    pub page: u32,
    /// Number of items per page
    pub per_page: u32,
    /// Total number of pages
    pub total_pages: u32,
    /// Whether there is a next page
    pub has_next: bool,
    /// Whether there is a previous page
    pub has_prev: bool,
}

impl IntegrationEventListResponseDto {
    /// Create a new list response from items and pagination info
    pub fn new(items: Vec<IntegrationEventResponseDto>, total: u64, page: u32, per_page: u32) -> Self {
        let total_pages = if per_page > 0 {
            ((total as f64) / (per_page as f64)).ceil() as u32
        } else {
            0
        };
        Self {
            items,
            total,
            page,
            per_page,
            total_pages,
            has_next: page < total_pages,
            has_prev: page > 1,
        }
    }
}

/// Summary DTO for list views (compact version)
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct IntegrationEventSummaryDto {
    pub id: Uuid,
    pub connector_id: Uuid,
    pub event_type: String,
    pub external_id: String,
    pub created_at: Option<DateTime<Utc>>,
}

// =============================================================================
// Conversions
// =============================================================================

impl From<IntegrationEvent> for IntegrationEventResponseDto {
    fn from(entity: IntegrationEvent) -> Self {
        Self {
            id: entity.id,
            connector_id: entity.connector_id,
            event_type: entity.event_type,
            external_id: entity.external_id,
            business_key: entity.business_key,
            status: entity.status,
            payload: entity.payload,
            mapped_ref_type: entity.mapped_ref_type,
            mapped_ref_id: entity.mapped_ref_id,
            error_detail: entity.error_detail,
            metadata: entity.metadata,
        }
    }
}

impl From<IntegrationEvent> for IntegrationEventSummaryDto {
    fn from(entity: IntegrationEvent) -> Self {
        let created_at = backbone_core::PersistentEntity::created_at(&entity);
        Self {
            id: entity.id,
            connector_id: entity.connector_id,
            event_type: entity.event_type,
            external_id: entity.external_id,
            created_at,
        }
    }
}

impl From<CreateIntegrationEventDto> for IntegrationEvent {
    fn from(dto: CreateIntegrationEventDto) -> Self {
        Self {
            id: Uuid::new_v4(),
            connector_id: dto.connector_id,
            event_type: dto.event_type,
            external_id: dto.external_id,
            business_key: dto.business_key,
            status: dto.status,
            payload: dto.payload,
            mapped_ref_type: dto.mapped_ref_type,
            mapped_ref_id: dto.mapped_ref_id,
            error_detail: dto.error_detail,
            metadata: AuditMetadata::default(),
        }
    }
}

impl From<&IntegrationEvent> for IntegrationEventResponseDto {
    fn from(entity: &IntegrationEvent) -> Self {
        Self {
            id: entity.id.clone(),
            connector_id: entity.connector_id.clone(),
            event_type: entity.event_type.clone(),
            external_id: entity.external_id.clone(),
            business_key: entity.business_key.clone(),
            status: entity.status.clone(),
            payload: entity.payload.clone(),
            mapped_ref_type: entity.mapped_ref_type.clone(),
            mapped_ref_id: entity.mapped_ref_id.clone(),
            error_detail: entity.error_detail.clone(),
            metadata: entity.metadata.clone(),
        }
    }
}

impl backbone_core::FromCreateDto<CreateIntegrationEventDto> for IntegrationEvent {
    fn from_create_dto(dto: CreateIntegrationEventDto) -> backbone_core::ServiceResult<Self> {
        Ok(IntegrationEvent::from(dto))
    }
}

impl backbone_core::ApplyUpdateDto<UpdateIntegrationEventDto> for IntegrationEvent {
    fn apply_update(mut self, dto: UpdateIntegrationEventDto) -> backbone_core::ServiceResult<Self> {
        self.connector_id = dto.connector_id;
        self.event_type = dto.event_type;
        self.external_id = dto.external_id;
        self.business_key = dto.business_key;
        self.status = dto.status;
        self.payload = dto.payload;
        self.mapped_ref_type = dto.mapped_ref_type;
        self.mapped_ref_id = dto.mapped_ref_id;
        self.error_detail = dto.error_detail;
        Ok(self)
    }
}

// =============================================================================
// Custom DTOs
// =============================================================================

// <<< CUSTOM DTOs
// Add custom DTOs specific to IntegrationEvent here.
// This section will be preserved during regeneration.
// >>> END CUSTOM DTOs