<?php

declare(strict_types=1);

namespace Seka\Vzdelavanie\Listeners\Testovanie;

use Seka\Vzdelavanie\Models\Popularita\Popularita;
use Seka\Vzdelavanie\Events\Testovanie\TestGenerated;

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

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