<?php

declare(strict_types=1);

namespace App\Repository\Domain\TopicTrustFlow;

use App\Entity\Domain\TopicTrustFlow;
use App\Service\Domain\TopicTrustFlowRepositoryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

final class DoctrineTopicTrustFlowRepository extends ServiceEntityRepository implements TopicTrustFlowRepositoryInterface
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, TopicTrustFlow::class);
    }

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

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

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