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::BoothBooking;
use crate::domain::entity::AuditMetadata;
use crate::domain::entity::EventBoothBookingStatus;
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct CreateBoothBookingDto {
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "event_booth_id")]
pub event_booth_id: Uuid,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "sale_order_line_id")]
pub sale_order_line_id: Option<Uuid>,
pub status: EventBoothBookingStatus,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "partner_id")]
pub partner_id: Option<Uuid>,
#[cfg_attr(feature = "validation", validate(length(max = 200)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "contact_name")]
pub contact_name: Option<String>,
#[cfg_attr(feature = "validation", validate(email, length(max = 254)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "contact_email")]
pub contact_email: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 40)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "contact_phone")]
pub contact_phone: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct UpdateBoothBookingDto {
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "event_booth_id")]
pub event_booth_id: Uuid,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "sale_order_line_id")]
pub sale_order_line_id: Option<Uuid>,
pub status: EventBoothBookingStatus,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "partner_id")]
pub partner_id: Option<Uuid>,
#[cfg_attr(feature = "validation", validate(length(max = 200)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "contact_name")]
pub contact_name: Option<String>,
#[cfg_attr(feature = "validation", validate(email, length(max = 254)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "contact_email")]
pub contact_email: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 40)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "contact_phone")]
pub contact_phone: Option<String>,
}
#[derive(Debug, Clone, Default, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct PatchBoothBookingDto {
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "event_booth_id")]
pub event_booth_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none", alias = "sale_order_line_id")]
pub sale_order_line_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<EventBoothBookingStatus>,
#[serde(skip_serializing_if = "Option::is_none", alias = "partner_id")]
pub partner_id: Option<Uuid>,
#[cfg_attr(feature = "validation", validate(length(max = 200)))]
#[serde(skip_serializing_if = "Option::is_none", alias = "contact_name")]
pub contact_name: Option<String>,
#[cfg_attr(feature = "validation", validate(email, length(max = 254)))]
#[serde(skip_serializing_if = "Option::is_none", alias = "contact_email")]
pub contact_email: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 40)))]
#[serde(skip_serializing_if = "Option::is_none", alias = "contact_phone")]
pub contact_phone: Option<String>,
}
impl PatchBoothBookingDto {
pub fn has_changes(&self) -> bool {
self.event_booth_id.is_some() || self.sale_order_line_id.is_some() || self.status.is_some() || self.partner_id.is_some() || self.contact_name.is_some() || self.contact_email.is_some() || self.contact_phone.is_some()
}
}
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct BoothBookingResponseDto {
#[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 event_booth_id: Uuid,
pub sale_order_line_id: Option<Uuid>,
pub status: EventBoothBookingStatus,
pub partner_id: Option<Uuid>,
pub contact_name: Option<String>,
pub contact_email: Option<String>,
pub contact_phone: Option<String>,
pub metadata: AuditMetadata,
}
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct BoothBookingListResponseDto {
pub items: Vec<BoothBookingResponseDto>,
pub total: u64,
pub page: u32,
pub per_page: u32,
pub total_pages: u32,
pub has_next: bool,
pub has_prev: bool,
}
impl BoothBookingListResponseDto {
pub fn new(items: Vec<BoothBookingResponseDto>, 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,
}
}
}
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct BoothBookingSummaryDto {
pub id: Uuid,
pub event_booth_id: Uuid,
pub sale_order_line_id: Option<Uuid>,
pub status: EventBoothBookingStatus,
pub created_at: Option<DateTime<Utc>>,
}
impl From<BoothBooking> for BoothBookingResponseDto {
fn from(entity: BoothBooking) -> Self {
Self {
id: entity.id,
event_booth_id: entity.event_booth_id,
sale_order_line_id: entity.sale_order_line_id,
status: entity.status,
partner_id: entity.partner_id,
contact_name: entity.contact_name,
contact_email: entity.contact_email,
contact_phone: entity.contact_phone,
metadata: entity.metadata,
}
}
}
impl From<BoothBooking> for BoothBookingSummaryDto {
fn from(entity: BoothBooking) -> Self {
let created_at = backbone_core::PersistentEntity::created_at(&entity);
Self {
id: entity.id,
event_booth_id: entity.event_booth_id,
sale_order_line_id: entity.sale_order_line_id,
status: entity.status,
created_at,
}
}
}
impl From<CreateBoothBookingDto> for BoothBooking {
fn from(dto: CreateBoothBookingDto) -> Self {
Self {
id: Uuid::new_v4(),
event_booth_id: dto.event_booth_id,
sale_order_line_id: dto.sale_order_line_id,
status: dto.status,
partner_id: dto.partner_id,
contact_name: dto.contact_name,
contact_email: dto.contact_email,
contact_phone: dto.contact_phone,
metadata: AuditMetadata::default(),
}
}
}
impl From<&BoothBooking> for BoothBookingResponseDto {
fn from(entity: &BoothBooking) -> Self {
Self {
id: entity.id.clone(),
event_booth_id: entity.event_booth_id.clone(),
sale_order_line_id: entity.sale_order_line_id.clone(),
status: entity.status.clone(),
partner_id: entity.partner_id.clone(),
contact_name: entity.contact_name.clone(),
contact_email: entity.contact_email.clone(),
contact_phone: entity.contact_phone.clone(),
metadata: entity.metadata.clone(),
}
}
}
impl backbone_core::FromCreateDto<CreateBoothBookingDto> for BoothBooking {
fn from_create_dto(dto: CreateBoothBookingDto) -> backbone_core::ServiceResult<Self> {
Ok(BoothBooking::from(dto))
}
}
impl backbone_core::ApplyUpdateDto<UpdateBoothBookingDto> for BoothBooking {
fn apply_update(mut self, dto: UpdateBoothBookingDto) -> backbone_core::ServiceResult<Self> {
self.event_booth_id = dto.event_booth_id;
self.sale_order_line_id = dto.sale_order_line_id;
self.status = dto.status;
self.partner_id = dto.partner_id;
self.contact_name = dto.contact_name;
self.contact_email = dto.contact_email;
self.contact_phone = dto.contact_phone;
Ok(self)
}
}