<?php


namespace App\Model\Facades\Readers;


use App\Model\Entities\GameData\Studio;
use App\Model\Exceptions\Db\RecordNotFoundException;
use App\Model\Services\StudioService;
use Kdyby\Doctrine\QueryBuilder;

class StudioReader extends BaseReader
{
    /** @var StudioService */
    protected $studioService;

    public function __construct(StudioService $studioService)
    {
        $this->studioService = $studioService;
    }

    /**
     * @return Studio[]
     */
    public function getStudios() : array
    {
        return $this->studioService->getStudios();
    }

    /**
     * @param int $id
     * @return Studio
     * @throws RecordNotFoundException
     */
    public function findStudioById(int $id) : Studio
    {
        $studio = $this->studioService->findStudioById($id);
        $this->validateEntity($studio);

        return $studio;
    }

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

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

    /**
     * @param int|Studio $studio
     * @return Studio
     */
    public function validateStudio($studio) : Studio
    {
        if ($studio instanceof Studio) {

            return $studio;
        }

        return $this->findStudioById($studio);
    }

}