<?php
/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 01.09.2020
 * Time: 17:14
 */

namespace Diamond\Repositories\ContentTag;

use Diamond\Domain\ContentTag\ContentTagCollection;
use Diamond\Domain\ContentTag\Contracts\ContentTagCriteriaInterface;
use Diamond\Domain\ContentTag\Contracts\ContentTagRepositoryInterface;
use Diamond\Infrastructure\Models\ContentTag\ContentTag;
use Diamond\Infrastructure\Models\ContentTag\ContentTagQuery;
use Diamond\Repositories\PropelAbstractRepository;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Repo\CollectionInterface;
use Repo\CrudRepositoryBuilderInterface;
use Repo\EntityInterface;
use Repo\PaginationInterface;

class ContentTagRepository extends PropelAbstractRepository implements ContentTagRepositoryInterface
{
    /**
     * @return EntityInterface
     */
    public static function createEntity(): EntityInterface
    {
        return new ContentTag();
    }

    /**
     * @return ModelCriteria
     */
    protected function createQuery(): ModelCriteria
    {
        return ContentTagQuery::create();
    }

    /**
     * @param PaginationInterface|ContentTagCriteriaInterface $criteria
     * @param ModelCriteria|ContentTagQuery $dbCriteria
     */
    protected function modifyCriteria(PaginationInterface $criteria, ModelCriteria $dbCriteria): void
    {
        $dbCriteria
            ->_if($criteria->getSearchByName() !== null)
            ->filterByName('%' . $criteria->getSearchByName() . '%', Criteria::LIKE)
            ->_endif();
    }


    protected function createCollection(): CollectionInterface
    {

        return new ContentTagCollection();
    }

}