<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Criteria\Zaznam;

use DateTimeInterface;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;

/**
 * Class ZaznamDatumBetweenCriteria
 *
 * @package Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Criteria\Zaznam
 */
final class ZaznamDatumBetweenCriteria implements CriteriaInterface
{
    /**
     * @var \DateTimeInterface
     */
    private DateTimeInterface $from;

    /**
     * @var \DateTimeInterface
     */
    private DateTimeInterface $to;

    /**
     * ZaznamDatumBetweenCriteria constructor.
     *
     * @param \DateTimeInterface $from
     * @param \DateTimeInterface $to
     */
    public function __construct(DateTimeInterface $from, DateTimeInterface $to)
    {
        $this->to = $to;
        $this->from = $from;
    }

    /**
     * @inheritDoc
     */
    public function apply($model, RepositoryInterface $repository)
    {
        return $model->whereBetween('datum', [$this->from, $this->to]);
    }
}
