<?php

namespace App\Listeners;

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

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

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