backbone-mail 0.2.32

Odoo mail core port — message/notification/followers/activity/alias/sms queue (schema: messaging)
//! DiscussChannel 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::DiscussChannel;
use crate::domain::entity::AuditMetadata;
use crate::domain::entity::DiscussChannelType;

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

/// Request DTO for creating a new DiscussChannel
///
/// 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 CreateDiscussChannelDto {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    #[serde(alias = "channel_type")]
    pub channel_type: DiscussChannelType,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub uuid: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "default_access_mode")]
    pub default_access_mode: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "avatar_128")]
    pub avatar_128: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "email_send")]
    pub email_send: bool,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub moderation: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "group_public_id")]
    pub group_public_id: Option<Uuid>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "alias_id")]
    pub alias_id: Option<Uuid>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "last_message_id")]
    pub last_message_id: Option<Uuid>,
}

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

/// Request DTO for full update of a DiscussChannel
///
/// 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 UpdateDiscussChannelDto {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    #[serde(alias = "channel_type")]
    pub channel_type: DiscussChannelType,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub uuid: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "default_access_mode")]
    pub default_access_mode: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "avatar_128")]
    pub avatar_128: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "email_send")]
    pub email_send: bool,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub moderation: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "group_public_id")]
    pub group_public_id: Option<Uuid>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "alias_id")]
    pub alias_id: Option<Uuid>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "last_message_id")]
    pub last_message_id: Option<Uuid>,
}

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

/// Request DTO for partial update of a DiscussChannel
///
/// 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 PatchDiscussChannelDto {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "channel_type")]
    pub channel_type: Option<DiscussChannelType>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub uuid: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "default_access_mode")]
    pub default_access_mode: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "avatar_128")]
    pub avatar_128: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "email_send")]
    pub email_send: Option<bool>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub moderation: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "group_public_id")]
    pub group_public_id: Option<Uuid>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "alias_id")]
    pub alias_id: Option<Uuid>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "last_message_id")]
    pub last_message_id: Option<Uuid>,
}

impl PatchDiscussChannelDto {
    /// Check if any field is set
    pub fn has_changes(&self) -> bool {
        self.name.is_some() || self.channel_type.is_some() || self.description.is_some() || self.uuid.is_some() || self.default_access_mode.is_some() || self.avatar_128.is_some() || self.email_send.is_some() || self.moderation.is_some() || self.group_public_id.is_some() || self.alias_id.is_some() || self.last_message_id.is_some()
    }
}

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

/// Response DTO for DiscussChannel 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 DiscussChannelResponseDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub id: Uuid,
    pub name: Option<String>,
    pub channel_type: DiscussChannelType,
    pub description: Option<String>,
    pub uuid: Option<String>,
    pub default_access_mode: Option<String>,
    pub avatar_128: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub email_send: bool,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub moderation: bool,
    pub group_public_id: Option<Uuid>,
    pub alias_id: Option<Uuid>,
    pub last_message_id: Option<Uuid>,
    pub metadata: AuditMetadata,
}

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

/// Paginated list response for DiscussChannel 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 DiscussChannelListResponseDto {
    /// List of items
    pub items: Vec<DiscussChannelResponseDto>,
    /// 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 DiscussChannelListResponseDto {
    /// Create a new list response from items and pagination info
    pub fn new(items: Vec<DiscussChannelResponseDto>, 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 DiscussChannelSummaryDto {
    pub id: Uuid,
    pub name: Option<String>,
    pub channel_type: DiscussChannelType,
    pub description: Option<String>,
    pub created_at: Option<DateTime<Utc>>,
}

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

impl From<DiscussChannel> for DiscussChannelResponseDto {
    fn from(entity: DiscussChannel) -> Self {
        Self {
            id: entity.id,
            name: entity.name,
            channel_type: entity.channel_type,
            description: entity.description,
            uuid: entity.uuid,
            default_access_mode: entity.default_access_mode,
            avatar_128: entity.avatar_128,
            email_send: entity.email_send,
            moderation: entity.moderation,
            group_public_id: entity.group_public_id,
            alias_id: entity.alias_id,
            last_message_id: entity.last_message_id,
            metadata: entity.metadata,
        }
    }
}

impl From<DiscussChannel> for DiscussChannelSummaryDto {
    fn from(entity: DiscussChannel) -> Self {
        let created_at = backbone_core::PersistentEntity::created_at(&entity);
        Self {
            id: entity.id,
            name: entity.name,
            channel_type: entity.channel_type,
            description: entity.description,
            created_at,
        }
    }
}

impl From<CreateDiscussChannelDto> for DiscussChannel {
    fn from(dto: CreateDiscussChannelDto) -> Self {
        Self {
            id: Uuid::new_v4(),
            name: dto.name,
            channel_type: dto.channel_type,
            description: dto.description,
            uuid: dto.uuid,
            default_access_mode: dto.default_access_mode,
            avatar_128: dto.avatar_128,
            email_send: dto.email_send,
            moderation: dto.moderation,
            group_public_id: dto.group_public_id,
            alias_id: dto.alias_id,
            last_message_id: dto.last_message_id,
            metadata: AuditMetadata::default(),
        }
    }
}

impl From<&DiscussChannel> for DiscussChannelResponseDto {
    fn from(entity: &DiscussChannel) -> Self {
        Self {
            id: entity.id.clone(),
            name: entity.name.clone(),
            channel_type: entity.channel_type.clone(),
            description: entity.description.clone(),
            uuid: entity.uuid.clone(),
            default_access_mode: entity.default_access_mode.clone(),
            avatar_128: entity.avatar_128.clone(),
            email_send: entity.email_send.clone(),
            moderation: entity.moderation.clone(),
            group_public_id: entity.group_public_id.clone(),
            alias_id: entity.alias_id.clone(),
            last_message_id: entity.last_message_id.clone(),
            metadata: entity.metadata.clone(),
        }
    }
}

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

impl backbone_core::ApplyUpdateDto<UpdateDiscussChannelDto> for DiscussChannel {
    fn apply_update(mut self, dto: UpdateDiscussChannelDto) -> backbone_core::ServiceResult<Self> {
        self.name = dto.name;
        self.channel_type = dto.channel_type;
        self.description = dto.description;
        self.uuid = dto.uuid;
        self.default_access_mode = dto.default_access_mode;
        self.avatar_128 = dto.avatar_128;
        self.email_send = dto.email_send;
        self.moderation = dto.moderation;
        self.group_public_id = dto.group_public_id;
        self.alias_id = dto.alias_id;
        self.last_message_id = dto.last_message_id;
        Ok(self)
    }
}

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

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