<?php

declare(strict_types=1);

namespace Seka\Vzdelavanie\Listeners\Testovanie;

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

/**
 * Class TestCreatePopularityRecord
 *
 * @package Seka\Vzdelavanie\Listeners\Testovanie
 */
final class TestCreatePopularityRecord implements ShouldQueue
{
    /**
     * @param \Seka\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);
    }
}
