<?php

declare(strict_types=1);

namespace App\Listeners;

use App\Models\ActivityLogNamesEnum;
use Illuminate\Contracts\Queue\ShouldQueue;
use Seka\Vzdelavanie\Models\Kniznica\Kategoria;
use Seka\Vzdelavanie\Events\Kniznica\KategoriaActionEvent;

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