<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Vzdelavanie\Listeners\Testovanie;

use Illuminate\Contracts\Queue\ShouldQueue;
use Seka\Portal\Modul\Vzdelavanie\Events\Testovanie\Frontend\TestGenerated;
use Seka\Portal\Modul\Vzdelavanie\Models\Popularita\Popularita;

/**
 * Class TestCreatePopularityRecord
 *
 * @package Seka\Portal\Modul\Vzdelavanie\Listeners\Testovanie
 */
final class TestCreatePopularityRecord implements ShouldQueue
{
    /**
     * @param \Seka\Portal\Modul\Vzdelavanie\Events\Testovanie\Frontend\TestGenerated $event
     */
    public function handle(TestGenerated $event): void
    {
        $popularita = new Popularita();
        $popularita->pouzivatel()->associate($event->pouzivatel->getAuthIdentifier());

        $event->test->popularita()->save($popularita);
    }
}
