<?php

namespace App\Listeners;

use App\Events\PaymentCompleted;
use App\Models\Course;
use App\Notifications\CoursePaid;

class SendVirtualAccountPaidNotification
{
    public function handle(PaymentCompleted $event): void
    {
        $payment = $event->payment;
        $user = $payment->user;

        $courseIds = json_decode($payment->items, true);
        $courses = Course::whereIn('id', $courseIds)->get();

        $user->notify(
            new CoursePaid($payment, $courses)
        );
    }
}
