booking->isInternal(); } public function activities(CaseContext $case): array { $booking = $case->booking; if ($case->profile->documents() === Responsibility::Portal) { return [new Activity('documents', 'Buchungsunterlagen an den Gast', ActivityState::External)]; } $binding = $case->binding; $state = match (true) { $booking->confirmation_sent_at !== null => ActivityState::Done, ! $binding => ActivityState::Later, $booking->confirmation_failed_at !== null => ActivityState::Problem, default => ActivityState::Open, }; $missing = $binding && $state === ActivityState::Open ? app(CaseAutomation::class)->documentBlockers($booking) : []; // What the landlord still has to confirm (unreleased texts, terms not shown to be agreed on the portal). $toConfirm = $binding && $state === ActivityState::Open && $missing === [] ? app(SendBookingDocuments::class)->compose($booking)->toConfirm() : []; return [new Activity('documents', match (true) { $state !== ActivityState::Open => $case->inquiry ? 'Buchungsbestätigung mit Vertrag senden' : 'Buchungsunterlagen an den Gast senden', $case->inquiry => 'Buchungsbestätigung mit Vertrag prüfen und senden', default => 'Buchungsunterlagen prüfen und senden', }, $case->later($missing !== [] ? ActivityState::Waiting : $state), match (true) { $booking->confirmation_sent_at !== null => 'gesendet am '.$booking->confirmation_sent_at->format('d.m.Y'), $state === ActivityState::Problem => 'Versand fehlgeschlagen', $missing !== [] => 'wartet: '.implode(' ', $missing), $toConfirm !== [] => 'vor dem Versand zu prüfen: '.implode(' ', $toConfirm), default => null, }, match (true) { $state === ActivityState::Problem => 'resendConfirmation', $binding && $missing === [] && $booking->confirmation_sent_at === null => 'sendDocuments', default => null, })]; } /** The guest's e-mail and the price are what the documents need – not every detail of a request. */ public function due(CaseContext $case): bool { $booking = $case->booking; return $booking->processingMode() === ProcessingMode::Automatic && $case->binding && $booking->confirmation_sent_at === null && $case->profile->documents() === Responsibility::Landlord && $case->profile->origin !== 'migration'; } public function blockers(CaseContext $case): array { return app(CaseAutomation::class)->documentBlockers($case->booking); } public function run(CaseContext $case): StepResult { $reasons = app(SendBookingDocuments::class)->automatically($case->booking); return $reasons === [] ? StepResult::ran() : StepResult::blocked($reasons); } public function isOutward(): bool { return true; } }