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 MailRegistration entities
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Type alias over `GenericCrudService` — all CRUD logic lives in backbone-core.
//! For custom behaviour, create `mail_registration_service_custom.rs` (preserved on regen).

use backbone_core::GenericCrudService;

use crate::presentation::dto::{CreateMailRegistrationDto, UpdateMailRegistrationDto};
use crate::domain::entity::MailRegistration;
use crate::infrastructure::persistence::MailRegistrationRepository;

/// Application service for MailRegistration 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 `mail_registration_service_custom.rs`:
///
/// ```rust,ignore
/// pub struct MailRegistrationServiceCustom {
///     inner: Arc<MailRegistrationService>,
///     // add domain-specific dependencies here
/// }
/// ```
pub type MailRegistrationService = GenericCrudService<
    MailRegistration,
    CreateMailRegistrationDto,
    UpdateMailRegistrationDto,
    MailRegistrationRepository,
>;

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

#[async_trait::async_trait]
impl backbone_core::write_guard::WriteGuard<MailRegistration> for MailRegistrationRowRules {
    async fn check(
        &self,
        ctx: &backbone_core::write_guard::WriteCtx<'_, MailRegistration>,
    ) -> 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();
        // `scheduler_id_required` (@required on MailRegistration.scheduler_id)
        if (create || (update && r::changed(old.as_ref(), row, &["scheduler_id"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "scheduler_id")), r::not(r::is_empty(r::trim(r::field(row, "scheduler_id")))))) {
            refuse.push(Violation::new("scheduler_id", "required", "scheduler_id is required"));
        }
        // `registration_id_required` (@required on MailRegistration.registration_id)
        if (create || (update && r::changed(old.as_ref(), row, &["registration_id"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "registration_id")), r::not(r::is_empty(r::trim(r::field(row, "registration_id")))))) {
            refuse.push(Violation::new("registration_id", "required", "registration_id is required"));
        }
        // `outcome_max_length` (@max(40) on MailRegistration.outcome)
        if (create || (update && r::changed(old.as_ref(), row, &["outcome"]))) && !r::holds(&r::le(r::length(r::field(row, "outcome")), r::Val::Num(40.0_f64))) {
            refuse.push(Violation::new("outcome", "max_length", "outcome must be at most 40 characters").with_param("max", 40_i64));
        }
        GuardOutcome { refuse, shadow }
    }
}