<?php

/*
 * 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\BrevoConfiguration;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

    public function get(): ?BrevoConfiguration
    {
        return $this->find(BrevoConfiguration::SINGLETON_ID);
    }

    public function getOrCreate(): BrevoConfiguration
    {
        return $this->get() ?? new BrevoConfiguration();
    }

    public function save(BrevoConfiguration $configuration): void
    {
        $this->getEntityManager()->persist($configuration);
        $this->getEntityManager()->flush();
    }
}
