<?php

namespace App\Http\Controllers;

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

/**
 * Class InformaciaController
 */
final class InformaciaController extends Controller
{
    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.
     */
    public function index(): Renderable
    {
        return view('pages.frontend.informacie.index');
    }

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

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