<?php

namespace App\Listeners\Posts;

use App\Events\Posts\ArtworkShared;
use App\Notifications\ArtworkSharedNotification;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendArtworkSharedNotification implements ShouldQueue
{
    public function handle(ArtworkShared $event): void
    {
        // Notify the artwork's original owner
        $originalOwner = $event->artwork->user;

        // Don't notify if sharer is the owner
        if ($originalOwner->id === $event->sharer->id) {
            return;
        }

        $originalOwner->notify(new ArtworkSharedNotification(
            post:    $event->post,
            artwork: $event->artwork,
            sharer:  $event->sharer,
        ));
    }
}
