<?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
 */
final class AktivitaVzdelavanieKniznicaSekciaUcebnehoMaterialu
{
    public function handle(SekciaActionEvent $event): void
    {
        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));
    }
}
