<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Vzdelavanie\Listeners\Kniznica;

use Illuminate\Contracts\Queue\ShouldQueue;
use Seka\Portal\Modul\Vzdelavanie\Enums\ActivityLogNamesEnum;
use Seka\Portal\Modul\Vzdelavanie\Events\Kniznica\KategoriaActionEvent;
use Seka\Portal\Modul\Vzdelavanie\Models\Kniznica\Kategoria;

/**
 * Class AktivitaVzdelavanieKniznicaKategoria
 *
 * @package Seka\Portal\Modul\Vzdelavanie\Listeners\Kniznica
 */
final class AktivitaVzdelavanieKniznicaKategoria implements ShouldQueue
{
    public function handle(KategoriaActionEvent $event): void
    {
        activity()
            ->by($event->pouzivatel)
            ->inLog(ActivityLogNamesEnum::VZDELAVANIE_KNIZNICA->name)
            ->performedOn(Kategoria::query()->find($event->kategoria->id))
            ->withProperties([
                'nazov' => $event->kategoria->nazov,
                'request' => [
                    'ip' => $event->request->get('REMOTE_ADDR'),
                    'user_agent' => $event->request->get('user-agent'),
                ],
            ])
            ->log(get_class($event));
    }
}
