<?php

// 4. Event Listener for Better Offline Detection
namespace App\Listeners;

use App\Services\PresenceService;
use Illuminate\Auth\Events\Logout;
use Illuminate\Contracts\Queue\ShouldQueue;

class HandleUserLogout implements ShouldQueue
{
    protected $presenceService;

    public function __construct(PresenceService $presenceService)
    {
        $this->presenceService = $presenceService;
    }

    public function handle(Logout $event)
    {
        $guard = $event->guard ?? 'web';

        if ($event->user) {
            $this->presenceService->setUserOffline($event->user, $guard);
        }
    }
}
