<?php


namespace App\Model\Facades\Readers;


use App\Model\Entities\GameData\Platform;
use App\Model\Exceptions\Db\RecordNotFoundException;
use App\Model\Services\PlatformService;
use Kdyby\Doctrine\QueryBuilder;

class PlatformReader extends BaseReader
{
    /** @var PlatformService */
    protected $platformService;

    /**
     * PlatformReader constructor.
     * @param PlatformService $platformService
     */
    public function __construct(PlatformService $platformService)
    {
        $this->platformService = $platformService;
    }

    /**
     * @return Platform[]
     */
    public function getPlatforms() : array
    {
        return $this->platformService->getPlatforms();
    }

    /**
     * @param int $id
     * @return Platform
     * @throws RecordNotFoundException
     */
    public function findPlatformById(int $id) : Platform
    {
        $platform = $this->platformService->findPlatformById($id);
        $this->validateEntity($platform);

        return $platform;
    }

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

    public function validatePlatform($platform) : Platform
    {
        if ($platform instanceof Platform) {
            return $platform;
        }

        return $this->findPlatformById($platform);
    }

}