<?php

namespace DMD\LaLigaApi\Repository;

use DMD\LaLigaApi\Entity\CustomRole;
use DMD\LaLigaApi\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<CustomRole>
 *
 * @method CustomRole|null find($id, $lockMode = null, $lockVersion = null)
 * @method CustomRole|null findOneBy(array $criteria, array $orderBy = null)
 * @method CustomRole[]    findAll()
 * @method CustomRole[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class CustomRoleRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, CustomRole::class);
    }

    public function findUserByRoleName(string $roleName): User
    {
        return $this->createQueryBuilder('r')
            ->select('u')
            ->join('r.user', 'u')
            ->where('r.name = :roleName')
            ->setParameter('roleName', $roleName)
            ->setMaxResults(1)
            ->getQuery()
            ->getResult();
    }

//    /**
//     * @return CustomRole[] Returns an array of CustomRole objects
//     */
//    public function findByExampleField($value): array
//    {
//        return $this->createQueryBuilder('c')
//            ->andWhere('c.exampleField = :val')
//            ->setParameter('val', $value)
//            ->orderBy('c.id', 'ASC')
//            ->setMaxResults(10)
//            ->getQuery()
//            ->getResult()
//        ;
//    }

//    public function findOneBySomeField($value): ?CustomRole
//    {
//        return $this->createQueryBuilder('c')
//            ->andWhere('c.exampleField = :val')
//            ->setParameter('val', $value)
//            ->getQuery()
//            ->getOneOrNullResult()
//        ;
//    }
}
