<?php

declare(strict_types=1);

namespace App\Repository;

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

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

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

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