56 lines
2.0 KiB
PHP
56 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
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 ReservationSubmittedNotification extends Notification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(
|
|
public readonly Reservation $reservation,
|
|
public readonly string $event = 'submitted',
|
|
) {
|
|
$this->afterCommit();
|
|
}
|
|
|
|
/** @return list<string> */
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['mail', 'database'];
|
|
}
|
|
|
|
public function toMail(object $notifiable): MailMessage
|
|
{
|
|
return (new MailMessage)
|
|
->subject($this->event === 'information_provided'
|
|
? "Resposta recebida para {$this->reservation->reference}"
|
|
: "Nova requisição {$this->reservation->reference}")
|
|
->greeting($this->event === 'information_provided'
|
|
? 'O requisitante respondeu ao pedido de esclarecimentos'
|
|
: 'Nova requisição para aprovação')
|
|
->line("{$this->reservation->requester->name} submeteu a requisição {$this->reservation->reference} para decisão.")
|
|
->line("Período: {$this->reservation->starts_at->format('d/m/Y H:i')} — {$this->reservation->ends_at->format('d/m/Y H:i')}.")
|
|
->action('Analisar requisição', url('/aprovacoes'));
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
public function toArray(object $notifiable): array
|
|
{
|
|
return [
|
|
'reservation_uuid' => $this->reservation->uuid,
|
|
'reference' => $this->reservation->reference,
|
|
'event' => $this->event,
|
|
'message' => $this->event === 'information_provided'
|
|
? "Foram prestados esclarecimentos para {$this->reservation->reference}."
|
|
: "Nova requisição {$this->reservation->reference} aguarda decisão.",
|
|
'url' => '/aprovacoes',
|
|
];
|
|
}
|
|
}
|