<?php

declare(strict_types=1);

namespace App\Notifications\Auth;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Config;

class ResetPasswordNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(
        public string $token
    ) {}

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

    public function toMail(object $notifiable): MailMessage
    {
        $appName = config('app.name');
        $url = url(route('password.reset', [
            'token' => $this->token,
            'email' => $notifiable->getEmailForPasswordReset(),
        ], false));

        $expireMinutes = Config::get('auth.passwords.'.Config::get('auth.defaults.passwords').'.expire', 60);

        return (new MailMessage)
            ->subject(__('Password Reset Request for :app', ['app' => $appName]))
            ->greeting(__('Dear :name,', ['name' => $notifiable->name ?? 'Valued Client']))
            ->line(__('We have received a formal request to reset the password associated with your :app account.', ['app' => $appName]))
            ->line(__('To authenticate this request and establish a new password, please click the button provided below. In accordance with our security protocols, this authorization link will expire in **:minutes minutes**.', ['minutes' => $expireMinutes]))
            ->action(__('Authorize Password Reset'), $url)
            ->line(__('If the button does not work, copy and paste this URL into your browser:'))
            ->line('`'.$url.'`')
            ->line(__('If you did not authorize this password reset request, please disregard this communication. Your account security remains intact, and no further action is required on your part.'))
            ->salutation(__('Sincerely,')."\n**".$appName." Security Operations**");
    }
}
