<?php

namespace App\Listeners;

use App\Events\UserLoggedOut;
use App\Models\ActivityLogNamesEnum;
use Illuminate\Contracts\Queue\ShouldQueue;

/**
 * Class AktivitaOdhlaseniaPouzivatela
 */
final class AktivitaOdhlaseniaPouzivatela implements ShouldQueue
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     */
    public function handle(UserLoggedOut $event): void
    {
        activity()
            ->by($event->pouzivatel)
            ->inLog(ActivityLogNamesEnum::SYSTEM->value)
            ->withProperties([
                'login' => $event->pouzivatel->login,
                'request' => [
                    'ip' => $event->request->get('REMOTE_ADDR'),
                    'user_agent' => $event->request->get('user-agent'),
                ],
            ])
            ->log(get_class($event));
    }
}
