<?php

declare(strict_types=1);

namespace App\Repository;

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

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

    public function countActifs(): int
    {
        return (int) $this->createQueryBuilder('theme')
            ->select('COUNT(theme.id)')
            ->andWhere('theme.actif = :actif')
            ->setParameter('actif', true)
            ->getQuery()
            ->getSingleScalarResult();
    }

    /**
     * @return list<Theme>
     */
    public function findActifs(): array
    {
        return $this->createQueryBuilder('theme')
            ->andWhere('theme.actif = :actif')
            ->setParameter('actif', true)
            ->orderBy('theme.createdAt', 'ASC')
            ->getQuery()
            ->getResult();
    }
}
