<?php

namespace App\Notifications;

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

class PasswordChangeOtpNotification extends Notification
{
    use Queueable;

    protected string $otp;

    /**
     * Create a new notification instance.
     */
    public function __construct(string $otp)
    {
        $this->otp = $otp;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @return array<int, string>
     */
    public function via(object $notifiable): array
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     */
    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage)
            ->subject('OTP Code for Password Change - ' . config('app.name'))
            ->greeting('Hello ' . $notifiable->name . ',')
            ->line('You are receiving this email because a password change was requested for your account.')
            ->line('Your OTP code is:')
            ->line('**' . $this->otp . '**')
            ->line('This code is valid for 10 minutes.')
            ->line('If you did not request this, please ignore this email and your password will remain unchanged.');
    }

    /**
     * Get the array representation of the notification.
     *
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return [
            'otp' => $this->otp,
        ];
    }
}
