<?php

namespace App\Listeners;

use App\Events\ReviewApproved;
use App\Events\ReviewCreated;
use App\Events\ReviewDeleted;
use App\Jobs\RecalculateProductRating;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class RecalculateRatingOnReviewChange implements ShouldQueue
{
    use InteractsWithQueue;

    /**
     * Handle the event.
     */
    public function handle(ReviewCreated|ReviewApproved|ReviewDeleted $event): void
    {
        // Dispatch job to recalculate product rating
        RecalculateProductRating::dispatch($event->review->product_id);
    }
}
