<?php

namespace App\Repository;

use App\Entity\User;
use App\Entity\Investigation;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

    /**
     * @return Investigation[] Returns an array of Investigation objects
     */
    public function findByStep($user, $value): array
    {
        return $this->createQueryBuilder('i')

            ->innerJoin('i.states', 's')

            ->where('i.create_by = :User')
            ->setParameter('User', $user)

            ->andWhere('s.step = :val')
            ->setParameter('val', $value)

            ->orderBy('i.id', 'ASC')

            ->getQuery()
            ->getResult()
        ;
    }

    public function findInvestigationAdminValidated(User $user): array
    {
        return $this->createQueryBuilder('INVES')
                
                ->where('INVES.create_by = :User')
                ->setParameter('User', $user)
                
				->andWhere('INVES.last_state = 20')

				->orderBy('INVES.id', 'ASC')

				->getQuery()
                ->getResult();
    }

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