<?php

declare(strict_types=1);

namespace App\Listeners;

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

/**
 * Class AktivitaVzdelavanieKniznicaUcebnyMaterial
 */
final class AktivitaVzdelavanieKniznicaUcebnyMaterial implements ShouldQueue
{
    public function handle(UcebnyMaterialActionEvent $event): void
    {
        activity()
            ->by($event->pouzivatel)
            ->inLog(ActivityLogNamesEnum::VZDELAVANIE_KNIZNICA->value)
            ->performedOn(Ucebnica::query()->find($event->ucebnica->id))
            ->withProperties([
                'nazov' => $event->ucebnica->nazov,
                'request' => [
                    'ip' => $event->request->get('REMOTE_ADDR'),
                    'user_agent' => $event->request->get('user-agent'),
                ],
            ])
            ->log(get_class($event));
    }
}
