<?php

declare(strict_types=1);

namespace App\Repository;

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

final class DocumentVersionRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, DocumentVersion::class);
    }

    /**
     * Streamingfähige Iteration über alle aktiven Versionen (für Global Reindex).
     *
     * @return iterable<DocumentVersion>
     */
    public function iterateActiveVersions(): iterable
    {
        $qb = $this->createQueryBuilder('v')
            ->andWhere('v.isActive = :active')
            ->setParameter('active', true)
            ->orderBy('v.createdAt', 'ASC');

        return $qb->getQuery()->toIterable();
    }
}
