<?php


namespace App\Model\Facades\Readers;


use App\Model\Entities\Image;
use App\Model\Services\ImageService;

class ImageReader extends BaseReader
{
    /** @var ImageService */
    protected $imageService;

    public function __construct(ImageService $imageService)
    {
        $this->imageService = $imageService;
    }

    public function findImageById(int $id) : Image
    {
        $image = $this->imageService->findImageById($id);
        $this->validateEntity($image);

        return $image;
    }

    public function validateImage($image) : Image
    {
        if ($image instanceof Image) {
            return $image;
        }

        return $this->findImageById($image);
    }
}