<?php

namespace App\Composers;

use App\Repositories\Eloquent\Criteria\AnyRolePouzivatelaCriteria;
use App\Repositories\Eloquent\Criteria\LatestCriteria;
use App\Repositories\Eloquent\Criteria\OrderByCasZverejneniaDescCriteria;
use App\Repositories\Eloquent\Criteria\SuggestedCriteria;
use App\Repositories\Eloquent\Criteria\ZverejneneCriteria;
use App\Repositories\InformaciaRepositoryContract;
use Illuminate\Contracts\View\View;
use Prettus\Repository\Exceptions\RepositoryException;

/**
 * Class LatestSuggestedInformationComposer
 *
 * @package \App\Composers
 */
final class LatestSuggestedInformationComposer
{
    /**
     * @var InformaciaRepositoryContract
     */
    private InformaciaRepositoryContract $repository;

    /**
     * @param InformaciaRepositoryContract $repository
     */
    public function __construct(InformaciaRepositoryContract $repository)
    {
        $this->repository = $repository;
    }

    /**
     * @param View $view
     * @return View
     * @throws RepositoryException
     */
    public function compose(View $view): View
    {
        $informacia = $this->repository
            ->pushCriteria(SuggestedCriteria::class)
            ->pushCriteria(LatestCriteria::class)
            ->pushCriteria(ZverejneneCriteria::class)
            ->pushCriteria(AnyRolePouzivatelaCriteria::class)
            ->pushCriteria(OrderByCasZverejneniaDescCriteria::class)
            ->limit(5);

        return $view->with(
            'aktualnaOdporucanaInformacia',
            $informacia,
        );
    }
}
