<?php

declare(strict_types=1);

namespace App\Notifications;

use App\Models\Story;
use App\Models\StoryComment;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;

class StoryMentionedNotification extends Notification
{
    use Queueable;

    public function __construct(
        private readonly Story $story,
        private readonly StoryComment $comment,
        private readonly User $actor,
    ) {}

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

    public function databaseType(object $notifiable): string
    {
        return 'story_mentioned';
    }

    public function toDatabase(object $notifiable): array
    {
        $label = $this->actor->name ?: $this->actor->username ?: 'Someone';

        return [
            'type' => 'story_mentioned',
            'story_id' => (int) $this->story->id,
            'story_title' => $this->story->title,
            'comment_id' => (int) $this->comment->id,
            'actor_id' => (int) $this->actor->id,
            'actor_name' => $this->actor->name,
            'actor_username' => $this->actor->username,
            'message' => $label . ' mentioned you in a story comment',
            'url' => route('stories.show', ['slug' => $this->story->slug]) . '#story-comment-' . $this->comment->id,
        ];
    }
}