<?php

declare(strict_types=1);

namespace App\Repository\Country;

use App\Entity\Country;
use App\Service\CountryRepositoryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

final class DoctrineCountryRepository extends ServiceEntityRepository implements CountryRepositoryInterface
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, Country::class);
    }

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

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

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