<?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;
        $job = $context['job'] ?? 'n/a';
        $queue = $context['queue'] ?? 'n/a';
        $eventId = $context['event_id'] ?? 'n/a';
        $photoId = $context['photo_id'] ?? 'n/a';
        $exception = $context['exception'] ?? 'n/a';
        $timestamp = now()->toDateTimeString();

        return (new MailMessage)
            ->subject(__('emails.upload_pipeline_failed.subject', ['job' => $job]))
            ->view('emails.notifications.basic', [
                'title' => __('emails.upload_pipeline_failed.subject', ['job' => $job]),
                'preheader' => __('emails.upload_pipeline_failed.preheader'),
                'heroTitle' => __('emails.upload_pipeline_failed.hero_title'),
                'heroSubtitle' => __('emails.upload_pipeline_failed.hero_subtitle'),
                'lines' => [
                    __('emails.upload_pipeline_failed.line_job', ['job' => $job]),
                    __('emails.upload_pipeline_failed.line_queue', ['queue' => $queue]),
                    __('emails.upload_pipeline_failed.line_event', ['event' => $eventId]),
                    __('emails.upload_pipeline_failed.line_photo', ['photo' => $photoId]),
                    __('emails.upload_pipeline_failed.line_exception', ['exception' => $exception]),
                    __('emails.upload_pipeline_failed.line_time', ['time' => $timestamp]),
                ],
                'footer' => __('emails.upload_pipeline_failed.footer'),
            ]);
    }
}
