<?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
 */
final class LatestSuggestedInformationComposer
{
    private InformaciaRepositoryContract $repository;

    public function __construct(InformaciaRepositoryContract $repository)
    {
        $this->repository = $repository;
    }

    /**
     * @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,
        );
    }
}
