<?php

namespace App\Repository\Campaign\Bolton;

use App\Entity\Campaign\Bolton;
use App\Service\Campaign\BoltonRepositoryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

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

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

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

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