<?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\AttendanceStash;

/**
 * @extends ServiceEntityRepository<AttendanceStash>
 *
 * @method AttendanceStash|null find($id, $lockMode = null, $lockVersion = null)
 * @method AttendanceStash|null findOneBy(array $criteria, array $orderBy = null)
 * @method AttendanceStash[]    findAll()
 * @method AttendanceStash[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class AttendanceStashRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, AttendanceStash::class);
    }

    public function findOrCreateDefault(): AttendanceStash
    {
        $stash = $this->findOneBy([]);
        if (!$stash) {
            $stash = new AttendanceStash();
        }

        return $stash;
    }
}
