<?php

namespace App\Http\Controllers;

use App\Repositories\Eloquent\Criteria\AnyRolePouzivatelaCriteria;
use App\Repositories\Eloquent\Criteria\ZverejneneCriteria;
use App\Repositories\InformaciaRepositoryContract;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Contracts\View\Factory;
use Illuminate\View\View;
use Prettus\Repository\Exceptions\RepositoryException;

/**
 * Class InformaciaController
 *
 * @package \App\Http\Controllers
 */
final class InformaciaController extends Controller
{
    /**
     * @var InformaciaRepositoryContract
     */
    private InformaciaRepositoryContract $informaciaRepository;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(InformaciaRepositoryContract $repository)
    {
        $this->middleware('auth');
        $this->informaciaRepository = $repository;
    }

    /**
     * Show the application dashboard.
     *
     * @return Renderable
     */
    public function index(): Renderable
    {
        return view('pages.frontend.informacia.livewire.index');
    }

    /**
     * @return Application|Factory|View
     * @throws RepositoryException
     */
    public function show(int $id): Renderable
    {
        $informacia = $this->informaciaRepository
            ->pushCriteria(ZverejneneCriteria::class)
            ->pushCriteria(AnyRolePouzivatelaCriteria::class)
            ->find($id);

        return view('pages.frontend.informacia.show')
            ->withInformacia($informacia);
    }
}
