<?php

declare(strict_types=1);

namespace App\Listeners;

use App\Models\ActivityLogNamesEnum;
use Illuminate\Contracts\Queue\ShouldQueue;
use Seka\Vzdelavanie\Events\Testovanie\Frontend\TestSpustenie;

/**
 * Class AktivitaVzdelavanieTestovanieSpustenieTestuPouzivatelom
 *
 * @package App\Listeners
 */
final class AktivitaVzdelavanieTestovanieSpustenieTestuPouzivatelom implements ShouldQueue
{
    /**
     * @param \Seka\Vzdelavanie\Events\Testovanie\Frontend\TestVyhodnotenie $event
     */
    public function handle(TestSpustenie $event)
    {
        activity()
            ->by($event->pouzivatel)
            ->inLog(ActivityLogNamesEnum::VZDELAVANIE_TESTY()->value)
            ->performedOn($event->test)
            ->withProperties([
                'nazov' => $event->test->nazov,
                'request' => [
                    'ip' => $event->request->get('REMOTE_ADDR'),
                    'user_agent' => $event->request->get('user-agent'),
                ],
            ])
            ->log(get_class($event));
    }
}
