66 lines
1.9 KiB
PHP
66 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Domain\Administration\Services\NotificationTemplateService;
|
|
use App\Domain\Reservations\Models\Reservation;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class ReservationDecisionNotification extends Notification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(
|
|
public readonly Reservation $reservation,
|
|
public readonly string $event,
|
|
public readonly ?string $comment = null,
|
|
) {
|
|
$this->afterCommit();
|
|
}
|
|
|
|
/** @return list<string> */
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['mail', 'database'];
|
|
}
|
|
|
|
public function toMail(object $notifiable): MailMessage
|
|
{
|
|
$template = $this->template();
|
|
$message = (new MailMessage)
|
|
->subject($template['subject'])
|
|
->greeting("Atualização da requisição {$this->reservation->reference}")
|
|
->line($template['message']);
|
|
|
|
if (filled($this->comment)) {
|
|
$message->line("Comentário: {$this->comment}");
|
|
}
|
|
|
|
return $message->action('Consultar requisições', url('/requisicoes'));
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
public function toArray(object $notifiable): array
|
|
{
|
|
$template = $this->template();
|
|
|
|
return [
|
|
'reservation_uuid' => $this->reservation->uuid,
|
|
'reference' => $this->reservation->reference,
|
|
'event' => $this->event,
|
|
'message' => $template['message'],
|
|
'comment' => $this->comment,
|
|
'url' => '/requisicoes',
|
|
];
|
|
}
|
|
|
|
/** @return array{subject:string,message:string} */
|
|
private function template(): array
|
|
{
|
|
return app(NotificationTemplateService::class)->render($this->event, $this->reservation, $this->comment);
|
|
}
|
|
}
|