36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Enums\BookingStatus;
|
|
use App\Exceptions\ReservationException;
|
|
use App\Mail\BookingDeclined;
|
|
use App\Models\Booking;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class DeclineBooking
|
|
{
|
|
/**
|
|
* @throws ReservationException
|
|
*/
|
|
public function handle(Booking $booking, bool $notifyGuest = true): void
|
|
{
|
|
if ($notifyGuest && blank($booking->guest?->email)) {
|
|
throw new ReservationException('Vor dem E-Mail-Versand bitte die E-Mail-Adresse des zugeordneten Gastes ergänzen.');
|
|
}
|
|
|
|
if (! in_array($booking->status, [BookingStatus::Reserved, BookingStatus::OfferSent, BookingStatus::Expired], true)) {
|
|
throw ReservationException::invalidTransition($booking->status->getLabel(), 'abgelehnt');
|
|
}
|
|
|
|
$booking->update([
|
|
'status' => BookingStatus::Declined,
|
|
'hold_expires_at' => null,
|
|
]);
|
|
|
|
if ($notifyGuest) {
|
|
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new BookingDeclined($booking));
|
|
}
|
|
}
|
|
}
|