<?php

declare(strict_types=1);

namespace App\Listeners;

use App\Models\ActivityLogNamesEnum;
use Illuminate\Contracts\Queue\ShouldQueue;
use Seka\Vzdelavanie\Models\Kniznica\Ucebnica;
use Seka\Vzdelavanie\Events\Kniznica\UcebnyMaterialActionEvent;

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