<?php

namespace App\Repository\Stat;

use App\Entity\Stat;
use App\Service\StatRepositoryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

final class DoctrineStatRepository extends ServiceEntityRepository implements StatRepositoryInterface
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, Stat::class);
    }

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

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

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