<?php

namespace App\Notifications;

use App\Models\User;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class NewUserRegistered extends Notification
{
    public function __construct(public User $newUser) {}

    public function via(object $notifiable): array
    {
        $ch = [];
        if ($notifiable->notificationPref('notif_new_user_reg'))   $ch[] = 'database';
        if ($notifiable->notificationPref('email_new_user_reg'))   $ch[] = 'mail';
        return $ch;
    }

    public function toArray(object $notifiable): array
    {
        return [
            'type'         => 'new_user',
            'user_id'      => $this->newUser->id,
            'user_name'    => $this->newUser->name,
            'user_email'   => $this->newUser->email,
            'user_avatar'  => $this->newUser->avatar_url,
            'user_channel' => $this->newUser->channel,
        ];
    }

    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage)
            ->subject('New member joined TAKEONE 🎉')
            ->view('emails.new-user-registered', [
                'newUser' => $this->newUser,
                'admin'   => $notifiable,
            ]);
    }
}
