<?php

declare(strict_types=1);

namespace App\Repository;

use App\Entity\Ecole;
use App\Entity\TypeFrais;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

    /** @return list<TypeFrais> */
    public function findActiveByEcole(Ecole $ecole): array
    {
        return $this->createQueryBuilder('t')
            ->andWhere('t.ecole = :ecole')
            ->andWhere('t.actif = :actif')
            ->setParameter('ecole', $ecole)
            ->setParameter('actif', true)
            ->orderBy('t.ordre', 'ASC')
            ->addOrderBy('t.libelle', 'ASC')
            ->getQuery()
            ->getResult();
    }
}
