<?php

namespace App\Resource\Repository;

use App\Resource\Entity\ResourcePool;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<ResourcePool>
 */
class ResourcePoolRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, ResourcePool::class);
    }

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

    /** @return ResourcePool[] */
    public function findForPair(string $entityType, int $entityId): array
    {
        return $this->createQueryBuilder('p')
            ->where('p.entityType = :type')
            ->andWhere('p.entityId = :id')
            ->setParameter('type', $entityType)
            ->setParameter('id', $entityId)
            ->orderBy('p.name', 'ASC')
            ->getQuery()
            ->getResult();
    }
}
