<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class UploadPipelineFailed extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(private readonly array $context)
    {
    }

    public function via(object $notifiable): array
    {
        $channels = [];

        if (config('storage-monitor.alert_recipients.mail')) {
            $channels[] = 'mail';
        }

        return $channels;
    }

    public function toMail(object $notifiable): MailMessage
    {
        $context = $this->context;

        return (new MailMessage)
            ->subject('Upload-Pipeline Fehler: '.($context['job'] ?? 'Unbekannter Job'))
            ->line('In der Upload-Pipeline ist ein Fehler aufgetreten.')
            ->line('Job: '.($context['job'] ?? 'n/a'))
            ->line('Queue: '.($context['queue'] ?? 'n/a'))
            ->line('Event ID: '.($context['event_id'] ?? 'n/a'))
            ->line('Foto ID: '.($context['photo_id'] ?? 'n/a'))
            ->line('Exception: '.($context['exception'] ?? 'n/a'))
            ->line('Zeitpunkt: '.now()->toDateTimeString());
    }
}
