<?php


namespace App\Model\Services;


use App\Model\Entities\Components\Gallery\Gallery;
use App\Model\Entities\Security\User;
use App\Model\Entities\Templates\GalleryTemplate;
use Kdyby\Doctrine\EntityRepository;

class GalleryService extends BaseService
{
    /** @var  EntityRepository */
    protected $galleries;

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

    /**
     * @param User $createdBy
     * @param GalleryTemplate $template
     * @param string $name
     * @param string $description
     * @return Gallery
     */
    public function createGallery(User $createdBy, GalleryTemplate $template, string $name, string $description = null) : Gallery
    {
        $gallery = new Gallery($createdBy);
        $gallery->setTemplate($template);
        $gallery->setName($name);
        $gallery->setDescription($description);

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

    /**
     * @param int $id
     * @return null|Gallery
     */
    public function findGalleryById(int $id)
    {
        return $this->galleries->find($id);
    }
}