<?php

namespace App\Notifications;

use App\Services\OtpService;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Notifications\Messages\MailMessage;

class VerifyEmailNotification extends VerifyEmail
{
    /**
     * Same signed link as Laravel's stock notification (verificationUrl(),
     * inherited from the parent), plus a 6-digit OTP code as an alternative
     * path — buildMailMessage() only receives the URL, not $notifiable, so
     * the code has to be generated here where $notifiable is in scope.
     */
    public function toMail($notifiable)
    {
        $url  = $this->verificationUrl($notifiable);
        $code = app(OtpService::class)->generateFor($notifiable);

        return (new MailMessage)
            ->subject('Verify Email Address')
            ->line('Please click the button below to verify your email address.')
            ->action('Verify Email Address', $url)
            ->line("Or enter this code instead: **{$code}**")
            ->line('This code expires in 10 minutes.')
            ->line('If you did not create an account, no further action is required.');
    }
}
