<?php

namespace App\Settlement\Repository;

use App\Payment\Entity\Payment;
use App\Settlement\Entity\FinancialBreakdown;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

    public function existsForPayment(Payment $payment): bool
    {
        return $this->count(['payment' => $payment]) > 0;
    }

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