<?php

namespace App\Representation\Repository;

use App\Auth\Entity\User;
use App\Representation\Entity\Representation;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

class RepresentationRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Representation::class);
    }

    public function findByUuid(string $uuid): ?Representation
    {
        return $this->findOneBy(['uuid' => $uuid]);
    }

    public function findByUser(User $user): ?Representation
    {
        return $this->findOneBy(['user' => $user]);
    }

    public function save(Representation $entity, bool $flush = true): void
    {
        $this->getEntityManager()->persist($entity);
        if ($flush) $this->getEntityManager()->flush();
    }

    public function remove(Representation $entity, bool $flush = true): void
    {
        $this->getEntityManager()->remove($entity);
        if ($flush) $this->getEntityManager()->flush();
    }
}
