<?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.
     */
    public function handle(UserLoggedIn $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));
    }
}
