<?php

namespace App\Modules\Core\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\URL;

class VerifyEmailNotification extends Notification
{
    use Queueable;

    /**
     * @return list<string>
     */
    public function via(object $notifiable): array
    {
        return ['mail'];
    }

    public function toMail(object $notifiable): MailMessage
    {
        $verificationUrl = URL::temporarySignedRoute(
            'verification.verify',
            now()->addMinutes(60),
            [
                'id' => $notifiable->getKey(),
                'hash' => sha1($notifiable->getEmailForVerification()),
            ]
        );

        $frontendUrl = rtrim((string) config('app.frontend_url'), '/')
            . '/verify-email?verification_url=' . urlencode($verificationUrl);

        return (new MailMessage())
            ->subject('Verify your BizNovia email')
            ->line('Verify your email address to secure your BizNovia account.')
            ->action('Verify Email', $frontendUrl)
            ->line('If you did not create a BizNovia account, no action is required.');
    }
}
