<?php


namespace App\Model\Facades\Readers;


use App\Model\Entities\GameData\Publisher;
use App\Model\Exceptions\Db\RecordNotFoundException;
use App\Model\Services\PublisherService;
use Kdyby\Doctrine\QueryBuilder;

class PublisherReader extends BaseReader
{
    /** @var PublisherService */
    protected $publisherService;

    public function __construct(PublisherService $publisherService)
    {
        $this->publisherService = $publisherService;
    }

    /**
     * @param $id
     * @return Publisher
     * @throws RecordNotFoundException
     */
    public function findPublisherById(int $id) : Publisher
    {
        $publisher = $this->publisherService->findPublisherById($id);
        $this->validateEntity($publisher);

        return $publisher;
    }

    /**
     * @return Publisher[]
     */
    public function getPublishers() : array
    {
        return $this->publisherService->getPublishers();
    }

    /**
     * @return array
     */
    public function getSelectBoxPairs() : array
    {
        return $this->publisherService->getSelectBoxPairs();
    }

    /**
     * @return QueryBuilder
     */
    public function getGridDataSource() : QueryBuilder
    {
        return $this->publisherService->getPlatformsGridDataSource();
    }

    /**
     * @param int|Publisher $publisher
     * @return Publisher
     */
    public function validatePublisher($publisher) : Publisher
    {
        if ($publisher instanceof Publisher) {
            return $publisher;
        }

        return $this->findPublisherById($publisher);
    }

}