<?php

declare(strict_types=1);

namespace App\Listeners;

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

/**
 * Class AktivitaVzdelavanieTestovanieGenerovanieTestuPouzivatelom
 *
 * @package App\Listeners
 */
final class AktivitaVzdelavanieTestovanieGenerovanieTestuPouzivatelom implements ShouldQueue
{
    /**
     * @param \Seka\Vzdelavanie\Events\Testovanie\Frontend\TestGenerated $event
     *
     * @return void
     */
    public function handle(TestGenerated $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));
    }
}
