<?php

namespace App\Listeners\Posts;

use App\Events\Posts\PostCommented;
use App\Notifications\PostCommentedNotification;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendPostCommentedNotification implements ShouldQueue
{
    public function handle(PostCommented $event): void
    {
        // Notify the post owner
        $postOwner = $event->post->user;

        // Don't notify for self-comments
        if ($postOwner->id === $event->commenter->id) {
            return;
        }

        $postOwner->notify(new PostCommentedNotification(
            post:      $event->post,
            comment:   $event->comment,
            commenter: $event->commenter,
        ));
    }
}
