<?php

namespace App\Billing\Repository;

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

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

    public function existsForInvoiceItem(int $invoiceItemId, int $insuranceKindClaimInsuranceId): bool
    {
        return $this->createQueryBuilder('ci')
            ->select('COUNT(ci.id)')
            ->join('ci.claim', 'c')
            ->where('ci.invoiceItemId = :iid')
            ->andWhere('c.insuranceId = :ins')
            ->setParameter('iid', $invoiceItemId)
            ->setParameter('ins', $insuranceKindClaimInsuranceId)
            ->getQuery()
            ->getSingleScalarResult() > 0;
    }
}
