<?php

declare(strict_types=1);

namespace App\Http\Controllers\Backend\Pouzivatelia;

use App\Http\Controllers\Controller;
use Spatie\Activitylog\Models\Activity;
use App\Repositories\PouzivatelRepositoryContract;

/**
 * Class AkciePouzivatelovController
 *
 * @package App\Http\Controllers\Backend\Pouzivatelia
 */
final class AkciePouzivatelovController extends Controller
{
    /**
     * @var \App\Repositories\PouzivatelRepositoryContract
     */
    private PouzivatelRepositoryContract $pouzivatelRepository;

    /**
     * AkciePouzivatelovController constructor.
     *
     * @param \App\Repositories\PouzivatelRepositoryContract $pouzivatelRepository
     */
    public function __construct(PouzivatelRepositoryContract $pouzivatelRepository)
    {
        $this->pouzivatelRepository = $pouzivatelRepository;
    }

    /**
     * @param int $pouzivatelId
     *
     * @return mixed
     */
    public function index(int $pouzivatelId)
    {
        $pouzivatel = $this->pouzivatelRepository->with('pracovisko')->find($pouzivatelId);
        $akcie = Activity::query()
            ->where('causer_id', $pouzivatel->id)
            ->orderByDesc('created_at')
            ->paginate();

        return view('pages.sprava.pouzivatelia.akcie.index')
            ->withPouzivatel($pouzivatel)
            ->withAkcie($akcie);
    }
}
