use std::sync::Arc; use uuid::Uuid; use holzleitner_domain::Delivery; use crate::error::ApplicationError; use crate::ports::{DeliveryAction, DeliveryRepository}; /// Vier Lifecycle-Übergänge an einer Lieferung — `Hold`, `Resume`, /// `Cancel`, `Complete`. Die Statusmaschine läuft im Repository unter /// Lock; dieser Use Case validiert die Begründungs-Pflichten vorab. pub struct ApplyDeliveryActionUseCase { repository: Arc, } impl ApplyDeliveryActionUseCase { pub fn new(repository: Arc) -> Self { Self { repository } } pub async fn execute( &self, delivery_id: Uuid, action: DeliveryAction, ) -> Result { match &action { DeliveryAction::Hold { reason } | DeliveryAction::Cancel { reason } => { if reason.trim().is_empty() { return Err(ApplicationError::Validation( "reason darf nicht leer sein".into(), )); } } DeliveryAction::Resume | DeliveryAction::Complete => {} } self.repository.apply_action(delivery_id, action).await } }