<?php

namespace App\Repository;

use App\Entity\Usrlog;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<Usrlog>
 *
 * @method Usrlog|null find($id, $lockMode = null, $lockVersion = null)
 * @method Usrlog|null findOneBy(array $criteria, array $orderBy = null)
 * @method Usrlog[]    findAll()
 * @method Usrlog[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class UsrlogRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Usrlog::class);
    }

    /**
     * @throws ORMException
     * @throws OptimisticLockException
     */
    public function add(Usrlog $entity, bool $flush = true): void
    {
        if (!$entity->getCreatedAt()) {
            $entity->setCreatedAt(new \DateTime());
        }

        $this->_em->persist($entity);
        if ($flush) {
            $this->_em->flush();
        }
    }

    /**
     * @throws ORMException
     * @throws OptimisticLockException
     */
    public function remove(Usrlog $entity, bool $flush = true): void
    {
        $this->_em->remove($entity);
        if ($flush) {
            $this->_em->flush();
        }
    }
}
