<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Repository;

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Ferienpass\CoreBundle\Entity\AttendanceExtraFile;

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

    /**
     * Staged uploads (no attendance) that were never adopted by an application.
     *
     * @return array<int, AttendanceExtraFile>
     */
    public function findStaleStaged(\DateTimeImmutable $before): array
    {
        return $this->createQueryBuilder('f')
            ->andWhere('f.attendance IS NULL')
            ->andWhere('f.createdAt < :before')
            ->setParameter('before', $before)
            ->getQuery()
            ->getResult()
        ;
    }
}
