<?php

namespace App\Notifications;

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

class InactiveTenantDeletionWarning extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(private readonly Tenant $tenant, private readonly Carbon $plannedDeletion)
    {
        $this->afterCommit();
    }

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

    public function toMail(object $notifiable): MailMessage
    {
        $locale = $this->tenant->user?->preferred_locale ?? app()->getLocale();
        $formattedDate = $this->plannedDeletion->copy()->locale($locale)->translatedFormat('d. F Y');
        $subject = __('profile.retention.warning_subject', [], $locale);

        return (new MailMessage)
            ->subject($subject)
            ->view('emails.notifications.basic', [
                'title' => $subject,
                'preheader' => __('profile.retention.line1', ['name' => $this->tenant->name], $locale),
                'heroTitle' => $subject,
                'lines' => [
                    __('profile.retention.line1', ['name' => $this->tenant->name], $locale),
                    __('profile.retention.line2', ['date' => $formattedDate], $locale),
                    __('profile.retention.line3', [], $locale),
                ],
                'cta' => [
                    [
                        'label' => __('profile.retention.action', [], $locale),
                        'url' => url('/login'),
                    ],
                ],
            ]);
    }
}
