<?php

namespace App\Repositories\Eloquent\Criteria;

use App\Models\Informacia\Enums\StavInformacieEnum;
use Illuminate\Database\Eloquent\Builder;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;

/**
 * Class StavInformacieCriteria
 */
class StavInformacieCriteria implements CriteriaInterface
{
    public function __construct(private readonly ?StavInformacieEnum $stav = null) {}

    /**
     * @param Builder $model
     */
    public function apply($model, RepositoryInterface $repository): Builder
    {
        if ($this->stav != null) {
            return $model->where('stav', '=', $this->stav);
        }

        return $model->whereIn('stav', StavInformacieEnum::cases());
    }
}