<?php

namespace App\Repository\Campaign\Level;

use App\Entity\Campaign\Level;
use App\Service\Campaign\LevelRepositoryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

final class DoctrineRepository extends ServiceEntityRepository implements LevelRepositoryInterface
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, Level::class);
    }

    public function findById(int $id): ?Level
    {
        return $this->findOneBy(['id' => $id]);
    }

    /**
     * @param Level $level
     *
     * @throws \Doctrine\ORM\ORMException
     * @throws \Doctrine\ORM\OptimisticLockException
     */
    public function save(Level $level): void
    {
        $this->_em->persist($level);
        $this->_em->flush();
    }

    /**
     * @param Level $level
     *
     * @throws \Doctrine\ORM\ORMException
     * @throws \Doctrine\ORM\OptimisticLockException
     */
    public function delete(Level $level): void
    {
        $this->_em->remove($level);
        $this->_em->flush();
    }
}
