<?php


namespace App\Model\Services;


use App\Model\Entities\Image;
use App\Model\Entities\Security\User;
use Kdyby\Doctrine\EntityRepository;

class ImageService extends BaseService
{
    /** @var  EntityRepository */
    protected $images;

    protected function startup()
    {
        $this->images = $this->getRepository(Image::class);
    }

    public function createImage(User $createdBy, string $name, string $fileName) : Image
    {
        $image = new Image($createdBy);
        $image->setName($name);
        $image->setFileName($fileName);

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

    /**
     * @param int $id
     * @return null|Image
     */
    public function findImageById(int $id)
    {
        return $this->images->find($id);
    }

}