<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

/**
 * Sends a 6-digit OTP code to the user for password reset (mobile flow).
 *
 * The OTP itself is generated + cached by AuthController::forgotPasswordSendOtp.
 * This notification is only responsible for delivering the code by email.
 */
class PasswordResetOtpNotification extends Notification
{
    use Queueable;

    public function __construct(
        public string $otp,
        public int $expiresInMinutes = 10,
    ) {}

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

    public function toMail(object $notifiable): MailMessage
    {
        // BrandingHelper resolves the admin's saved Site Name first and
        // strips literal "MailTrixy" leaks at the helper layer; the
        // previous `config('app.name', 'MailTrixy')` fallback meant
        // the source product name shipped in every password-reset
        // email when APP_NAME was unset or default.
        $appName = \App\Helpers\BrandingHelper::name();

        return (new MailMessage)
            ->subject("{$appName} — Password Reset Code")
            ->greeting('Hello!')
            ->line("Your password reset code is:")
            ->line("**{$this->otp}**")
            ->line("This code expires in {$this->expiresInMinutes} minutes.")
            ->line('If you did not request a password reset, you can safely ignore this email — your account is unaffected.')
            ->salutation("— {$appName}");
    }
}
