<?php

namespace App\Policy\Repository;

use App\Policy\Entity\Policy;
use App\Policy\Entity\PolicyVersionLog;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

    /** @return PolicyVersionLog[] */
    public function findForPolicy(Policy $policy): array
    {
        return $this->createQueryBuilder('l')
            ->where('l.policy = :policy')
            ->setParameter('policy', $policy)
            ->orderBy('l.version', 'ASC')
            ->getQuery()
            ->getResult();
    }
}
