<?php

declare(strict_types=1);

namespace App\Module\Mail\Infrastructure\Doctrine;

use App\Module\Mail\Domain\Entity\MailFolder;
use App\Module\Mail\Domain\Repository\MailFolderRepositoryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<MailFolder>
 */
class DoctrineMailFolderRepository extends ServiceEntityRepository implements MailFolderRepositoryInterface
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, MailFolder::class);
    }

    /**
     * @return list<MailFolder>
     */
    public function findAllOrderedByPath(): array
    {
        return $this->createQueryBuilder('f')
            ->orderBy('f.path', 'ASC')
            ->getQuery()
            ->getResult()
        ;
    }

    public function findByPath(string $path): ?MailFolder
    {
        return $this->findOneBy(['path' => $path]);
    }
}
