<?php

/*
 * This file is part of the VitiCore 2.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Depot\Repository;

use CpCreation\VitiCore\Depot\Model\Category;
use CpCreation\VitiCore\Repository\BaseRepository;
use Doctrine\Persistence\ManagerRegistry;

class CategoryRepository extends BaseRepository
{
    /**
     * @throws \ReflectionException
     */
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Category::class);
    }

    /**
     * @return array<int, Category>
     */
    public function findCategories(): array
    {
        return $this
            ->createQueryBuilder('cat')
            ->innerJoin('cat.depots', 'depot')
            ->andWhere('depot.disabled = FALSE')
            ->addOrderBy('cat.position', 'ASC')
            ->getQuery()
            ->getResult();
    }
}
