<?php

namespace App\Resource\Repository;

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

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

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

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

    /**
     * @param string[] $uuids
     * @return Skill[]
     */
    public function findByUuids(array $uuids): array
    {
        if ($uuids === []) {
            return [];
        }

        return $this->createQueryBuilder('s')
            ->where('s.uuid IN (:uuids)')
            ->setParameter('uuids', $uuids)
            ->getQuery()
            ->getResult();
    }
}
