<?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\UcebnyMaterialActionEvent;
use Seka\Portal\Modul\Vzdelavanie\Models\Kniznica\Ucebnica;

/**
 * Class AktivitaVzdelavanieKniznicaUcebnyMaterial
 *
 * @package Seka\Portal\Modul\Vzdelavanie\Listeners\Kniznica
 */
final class AktivitaVzdelavanieKniznicaUcebnyMaterial implements ShouldQueue
{
    public function handle(UcebnyMaterialActionEvent $event): void
    {
        $performedOnModel = Ucebnica::query()->find($event->ucebnica->id);

        activity()
            ->by($event->pouzivatel)
            ->inLog(ActivityLogNamesEnum::VZDELAVANIE_KNIZNICA->name)
            ->performedOn($performedOnModel)
            ->withProperties([
                'nazov' => $event->ucebnica->nazov,
                'request' => [
                    'ip' => $event->request->get('REMOTE_ADDR'),
                    'user_agent' => $event->request->get('user-agent'),
                ],
            ])
            ->log(get_class($event));
    }
}
