backbone-events 0.8.0

Events core + the sale/booth/crm/sms/desk overlay — registrations under one authoritative seat counter, the sale seam (order-minted registrations, forward-only paid heal, SO-cancel mirror cascade), booth bookings with the DB exclusivity wall, closed-vocabulary lead rules through a host sink port, the dual-channel (mail/sms) self-arming scheduler, and the exact-match desk verb (Odoo event port, core + overlay)
//! Application service for BoothBooking entities
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Type alias over `GenericCrudService` — all CRUD logic lives in backbone-core.
//! For custom behaviour, create `booth_booking_service_custom.rs` (preserved on regen).

use backbone_core::GenericCrudService;

use crate::presentation::dto::{CreateBoothBookingDto, UpdateBoothBookingDto};
use crate::domain::entity::BoothBooking;
use crate::infrastructure::persistence::BoothBookingRepository;

/// Application service for BoothBooking entities.
///
/// All 12 standard CRUD operations (list, create, get, update, patch,
/// soft_delete, restore, empty_trash, bulk_create, upsert, find_by_id,
/// list_deleted) are provided by `GenericCrudService`.
///
/// Custom extensions go in `booth_booking_service_custom.rs`:
///
/// ```rust,ignore
/// pub struct BoothBookingServiceCustom {
///     inner: Arc<BoothBookingService>,
///     // add domain-specific dependencies here
/// }
/// ```
pub type BoothBookingService = GenericCrudService<
    BoothBooking,
    CreateBoothBookingDto,
    UpdateBoothBookingDto,
    BoothBookingRepository,
>;

/// The rules the schema declares for BoothBooking, checked against the row a create or update
/// would store. The generated build attaches it to [`BoothBookingService`]. A refusing rule's
/// break answers 422; a rule in shadow is logged under `backbone::write_guard` and the
/// write goes ahead.
pub struct BoothBookingRowRules;

#[async_trait::async_trait]
impl backbone_core::write_guard::WriteGuard<BoothBooking> for BoothBookingRowRules {
    async fn check(
        &self,
        ctx: &backbone_core::write_guard::WriteCtx<'_, BoothBooking>,
    ) -> backbone_core::write_guard::GuardOutcome {
        use backbone_core::row_rule as r;
        use backbone_core::violation::Violation;
        use backbone_core::write_guard::{GuardOutcome, WriteKind};
        let (create, update) = (ctx.kind == WriteKind::Create, ctx.kind == WriteKind::Update);
        let Some(after) = ctx.after.filter(|_| create || update) else {
            return GuardOutcome::allow();
        };
        let Ok(row) = serde_json::to_value(after) else {
            return GuardOutcome::allow();
        };
        let row = &row;
        let old = ctx.before.and_then(|b| serde_json::to_value(b).ok());
        let shadow = Vec::new();
        let mut refuse = Vec::new();
        // `event_booth_id_required` (@required on BoothBooking.event_booth_id)
        if (create || (update && r::changed(old.as_ref(), row, &["event_booth_id"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "event_booth_id")), r::not(r::is_empty(r::trim(r::field(row, "event_booth_id")))))) {
            refuse.push(Violation::new("event_booth_id", "required", "event_booth_id is required"));
        }
        // `contact_name_max_length` (@max(200) on BoothBooking.contact_name)
        if (create || (update && r::changed(old.as_ref(), row, &["contact_name"]))) && !r::holds(&r::le(r::length(r::field(row, "contact_name")), r::Val::Num(200.0_f64))) {
            refuse.push(Violation::new("contact_name", "max_length", "contact_name must be at most 200 characters").with_param("max", 200_i64));
        }
        // `contact_email_max_length` (@max(254) on BoothBooking.contact_email)
        if (create || (update && r::changed(old.as_ref(), row, &["contact_email"]))) && !r::holds(&r::le(r::length(r::field(row, "contact_email")), r::Val::Num(254.0_f64))) {
            refuse.push(Violation::new("contact_email", "max_length", "contact_email must be at most 254 characters").with_param("max", 254_i64));
        }
        // `contact_email_email` (type email on BoothBooking.contact_email)
        if (create || (update && r::changed(old.as_ref(), row, &["contact_email"]))) && !r::holds(&r::matches(r::field(row, "contact_email"), "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$")) {
            refuse.push(Violation::new("contact_email", "email", "contact_email must be an email address"));
        }
        // `contact_phone_max_length` (@max(40) on BoothBooking.contact_phone)
        if (create || (update && r::changed(old.as_ref(), row, &["contact_phone"]))) && !r::holds(&r::le(r::length(r::field(row, "contact_phone")), r::Val::Num(40.0_f64))) {
            refuse.push(Violation::new("contact_phone", "max_length", "contact_phone must be at most 40 characters").with_param("max", 40_i64));
        }
        GuardOutcome { refuse, shadow }
    }
}