<?php

namespace App\Listeners;

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

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

    /**
     * Handle the event.
     *
     * @return void
     */
    public function handle(UserLoggedIn $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));
    }
}
