<?php

declare(strict_types=1);

namespace App\Listeners;

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

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