<?php

declare(strict_types=1);

namespace App\Listeners;

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

/**
 * Class AktivitaVzdelavanieKniznicaKategoria
 */
final class AktivitaVzdelavanieKniznicaKategoria implements ShouldQueue
{
    /**
     * @return void
     */
    public function handle(KategoriaActionEvent $event)
    {
        activity()
            ->by($event->pouzivatel)
            ->inLog(ActivityLogNamesEnum::VZDELAVANIE_KNIZNICA()->value)
            ->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));
    }
}
