<?php

declare(strict_types=1);

namespace App\Notifications;

use App\Models\Artwork;
use App\Models\ArtworkComment;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;

class ArtworkMentionedNotification extends Notification
{
    use Queueable;

    public function __construct(
        private readonly Artwork $artwork,
        private readonly ArtworkComment $comment,
        private readonly User $actor,
    ) {}

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

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

    public function toDatabase(object $notifiable): array
    {
        $label = $this->actor->name ?: $this->actor->username ?: 'Someone';
        $slug = Str::slug((string) ($this->artwork->slug ?: $this->artwork->title)) ?: (string) $this->artwork->id;

        return [
            'type' => 'artwork_mentioned',
            'artwork_id' => (int) $this->artwork->id,
            'artwork_title' => $this->artwork->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 an artwork comment',
            'url' => route('art.show', ['id' => $this->artwork->id, 'slug' => $slug]) . '#comment-' . $this->comment->id,
        ];
    }
}