<?php

declare(strict_types=1);

namespace App\Listeners;

use App\Models\ActivityLogNamesEnum;
use Seka\Vzdelavanie\Events\Kniznica\SekciaActionEvent;
use Seka\Vzdelavanie\Models\Kniznica\Sekcia;

/**
 * Class AktivitaVzdelavanieKniznicaSekciaUcebnehoMaterialu
 *
 * @package App\Listeners
 */
final class AktivitaVzdelavanieKniznicaSekciaUcebnehoMaterialu
{
    /**
     * @param \Seka\Vzdelavanie\Events\Kniznica\SekciaActionEvent $event
     *
     * @return void
     */
    public function handle(SekciaActionEvent $event)
    {
        activity()
            ->by($event->pouzivatel)
            ->inLog(ActivityLogNamesEnum::VZDELAVANIE_KNIZNICA()->value)
            ->performedOn(Sekcia::query()->find($event->sekcia->id))
            ->withProperties([
                'nazov' => $event->sekcia->nazov,
                'request' => [
                    'ip' => $event->request->get('REMOTE_ADDR'),
                    'user_agent' => $event->request->get('user-agent'),
                ],
            ])
            ->log(get_class($event));
    }
}
