<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use App\Models\Comment;

class NewCommentNotification extends Notification
{
    use Queueable;

    protected $comment;

    public function __construct(Comment $comment)
    {
        $this->comment = $comment;
    }

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

    public function toArray(object $notifiable): array
    {
        return[
            'type' => 'comment',
            'message' => $this->comment->user->name . ' commented on your post: "' . $this->comment->post->title . '"',
            
            'url' => $this->comment->post->route_url,
            
            'avatar' => $this->comment->user->avatar,
            'created_at' => now(),
        ];
    }
}