<?php

namespace App\Notifications;

use App\Models\Comment;
use App\Models\User;
use App\Models\Video;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;

class NewReplyNotification extends Notification
{
    public function __construct(
        public Video $video,
        public Comment $reply,
        public User $replier
    ) {}

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

    public function toArray(object $notifiable): array
    {
        return [
            'type'            => 'new_reply',
            'video_id'        => $this->video->id,
            'video_route_key' => $this->video->getRouteKey(),
            'video_title'     => $this->video->title,
            'video_thumbnail' => $this->video->thumbnail,
            'actor_id'        => $this->replier->id,
            'actor_name'      => $this->replier->name,
            'actor_avatar'    => $this->replier->avatar_url,
            'comment_preview' => Str::limit($this->reply->body, 80),
        ];
    }
}
