<?php

declare(strict_types=1);

namespace App\Module\Commercial\Infrastructure\Doctrine;

use App\Module\Commercial\Domain\Entity\PaymentType;
use App\Module\Commercial\Domain\Repository\PaymentTypeRepositoryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<PaymentType>
 */
class DoctrinePaymentTypeRepository extends ServiceEntityRepository implements PaymentTypeRepositoryInterface
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, PaymentType::class);
    }

    public function findById(int $id): ?PaymentType
    {
        return $this->find($id);
    }

    public function findAllOrdered(): array
    {
        return $this->createQueryBuilder('p')
            ->orderBy('p.position', 'ASC')
            ->addOrderBy('p.label', 'ASC')
            ->getQuery()
            ->getResult()
        ;
    }
}
