<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Marketing\Repository;

use CpCreation\VitiCore\Marketing\Model\AbandonedCartConfiguration;
use CpCreation\VitiCore\Repository\BaseRepository;
use Doctrine\Persistence\ManagerRegistry;

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

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