notify($ticket, 'issued', $this->message('issued', $ticket)); } public function ticketCalled(Ticket $ticket): void { $counter = $ticket->counter?->name ?? 'the counter'; $this->notify($ticket, 'called', $this->message('called', $ticket, [':counter' => $counter])); } public function customersAhead(Ticket $ticket, int $ahead): void { if ($ahead > 2) { return; } $this->notify($ticket, 'almost_ready', $this->message('almost_ready', $ticket, [':ahead' => (string) $ahead])); } public function ticketCompleted(Ticket $ticket): void { $feedbackUrl = route('qms.feedback.show', $ticket->qr_token); $this->notify($ticket, 'completed', $this->message('completed', $ticket, [':feedback_url' => $feedbackUrl])); } public function ticketMissed(Ticket $ticket): void { $this->notify($ticket, 'missed', $this->message('missed', $ticket)); } public function appointmentReminder(\App\Models\QueueAppointment $appointment): void { $message = "Reminder: your appointment at {$appointment->scheduled_at->format('M j, H:i')} is coming up. Ref: {$appointment->reference}"; $this->sendToContact($appointment->customer_phone, $appointment->customer_email, $message); } protected function notify(Ticket $ticket, string $event, string $message): void { if (! data_get($ticket->serviceQueue?->settings, 'notifications_enabled', true)) { return; } $this->sendToContact($ticket->customer_phone, $ticket->customer_email, $message); Log::info('Queue notification sent', [ 'event' => $event, 'ticket' => $ticket->ticket_number, ]); } protected function sendToContact(?string $phone, ?string $email, string $message): void { if ($phone) { $this->sms->send($phone, $message); } if ($email) { $this->email->send($email, 'Ladill Queue update', $message); } } /** * @param array $replace */ protected function message(string $key, Ticket $ticket, array $replace = []): string { $template = config("qms.notification_templates.{$key}", 'Queue update for ticket :ticket.'); $replace = array_merge([ ':ticket' => $ticket->ticket_number, ':queue' => $ticket->serviceQueue?->name ?? 'Queue', ], $replace); return str_replace(array_keys($replace), array_values($replace), $template); } }