<?php

namespace App\Notifications\Packages;

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

class EventPackageGalleryExpiredNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(private readonly EventPackage $eventPackage) {}

    public function via(object $notifiable): array
    {
        return ['mail'];
    }

    public function toMail(object $notifiable): MailMessage
    {
        $event = $this->eventPackage->event;
        $tenant = $event?->tenant;
        $package = $this->eventPackage->package;

        $eventName = $event?->name['de'] ?? $event?->name['en'] ?? $event?->name ?? __('emails.package_limits.event_fallback');
        $url = url('/tenant/events/'.($event?->slug ?? ''));
        $subject = __('emails.package_limits.gallery_expired.subject', [
            'event' => $eventName,
        ]);
        $greeting = __('emails.package_limits.gallery_expired.greeting', [
            'name' => $tenant?->name ?? __('emails.package_limits.team_fallback'),
        ]);

        return (new MailMessage)
            ->subject($subject)
            ->view('emails.notifications.basic', [
                'title' => $subject,
                'preheader' => $greeting,
                'heroTitle' => $greeting,
                'heroSubtitle' => $subject,
                'lines' => [
                    __('emails.package_limits.gallery_expired.body', [
                        'event' => $eventName,
                        'package' => $package?->getNameForLocale() ?? $package?->name ?? __('emails.package_limits.package_fallback'),
                        'date' => optional($this->eventPackage->gallery_expires_at)->toFormattedDateString(),
                    ]),
                ],
                'cta' => [
                    [
                        'label' => __('emails.package_limits.gallery_expired.action'),
                        'url' => $url,
                    ],
                ],
                'footer' => __('emails.package_limits.footer'),
            ]);
    }
}
