<?php

namespace App\Billing\Repository;

use App\Billing\Entity\Invoice;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

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

    public function findBySession(int $patientSessionId): ?Invoice
    {
        return $this->findOneBy(['patientSessionId' => $patientSessionId]);
    }

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