<?php

namespace App\Modules\HR\Loans\Listeners;

use App\Models\User;
use App\Modules\HR\Loans\Events\LoanApproved;
use App\Modules\HR\Loans\Notifications\LoanApprovedNotification;

class LoanNotificationListener
{
    public function handleApproved(LoanApproved $event): void
    {
        $event->loan->loadMissing('employee.user');
        $user = $event->loan->employee?->user;
        if ($user instanceof User) {
            $user->notify(new LoanApprovedNotification($event->loan));
        }
    }
}
