<?php

declare(strict_types=1);

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Marketing\Repository;

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

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

    public function findOneByEmail(string $email): ?ReviewSolicitationOptOut
    {
        return $this->findOneBy([
            'emailHash' => ReviewSolicitationOptOut::hashEmail($email),
        ]);
    }

    public function hasOptedOut(string $email): bool
    {
        return null !== $this->findOneByEmail($email);
    }
}
