<?php

declare(strict_types=1);

namespace Seka\Vzdelavanie\Listeners\Kniznica;

use Illuminate\Contracts\Queue\ShouldQueue;
use Seka\Vzdelavanie\Models\Popularita\Popularita;
use Seka\Vzdelavanie\Events\Kniznica\UcebnyMaterialOpened;

/**
 * Class UcebnyMaterialCreatePopularityRecord
 *
 * @package Seka\Vzdelavanie\Listeners\Kniznica
 */
final class UcebnyMaterialCreatePopularityRecord
{
    /**
     * UcebnyMaterialCreatePopularityRecord constructor.
     */
    public function __construct()
    {

    }

    /**
     * @param \Seka\Vzdelavanie\Events\Kniznica\UcebnyMaterialOpened $event
     */
    public function handle(UcebnyMaterialOpened $event): void
    {
        $popularita = new Popularita();
        $popularita->pouzivatel()->associate($event->pouzivatel->getAuthIdentifier());

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