<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\User\Repository;

use CpCreation\VitiCore\Repository\BaseRepository;
use CpCreation\VitiCore\User\Model\ImportedClientImport;
use Doctrine\Persistence\ManagerRegistry;

class ImportedClientImportRepository extends BaseRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, ImportedClientImport::class);
    }

    /**
     * @return list<ImportedClientImport>
     */
    public function findRecent(int $limit = 20): array
    {
        return $this->createQueryBuilder('client_import')
            ->orderBy('client_import.createdAt', 'DESC')
            ->setMaxResults($limit)
            ->getQuery()
            ->getResult();
    }

    public function findLatest(): ?ImportedClientImport
    {
        return $this->createQueryBuilder('client_import')
            ->orderBy('client_import.createdAt', 'DESC')
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult();
    }
}
