<?php

namespace Webkul\ScheduleCronBundle\Datasource;

use Oro\Bundle\PimDataGridBundle\Datasource\Datasource;
use Oro\Bundle\PimDataGridBundle\Datasource\ResultRecord\HydratorInterface;
use Webkul\ScheduleCronBundle\Repository\DetailDataMapping;

class DetailDatasource extends Datasource
{
    /** @var DetailDataMapping */
    protected $repository;

    /** @var CustomObjectIdHydrator */
    protected $hydrator;

    /** @var array */
    protected $parameters = [];

    /**
     * @param DetailDataMapping $om
     * @param HydratorInterface          $hydrator
     */
    public function __construct(DetailDataMapping $repository, HydratorInterface $hydrator)
    {
        $this->repository = $repository;
        $this->hydrator = $hydrator;
    }

    /**
     * @param string $method the query builder creation method
     * @param array  $config the query builder creation config
     *
     * @return Datasource
     */
    protected function initializeQueryBuilder($method, array $config = [])
    {
        $this->qb = $this->repository->$method('wem');
        
        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getResults()
    {
        return $this->hydrator->hydrate($this->qb);
    }
}
