<?php

namespace App\Repository;

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

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

    public function findRange(Bible $bible, array $passage): array
    {
        return $this->createQueryBuilder('b')
            ->andWhere('b.book = :book')
            ->andWhere('b.chapter = :chapter')
            ->andWhere('b.verse BETWEEN :verseStart AND :verseEnd')
            ->setParameter('book', $bible->getBook())
            ->setParameter('chapter', $bible->getChapter())
            ->setParameter('verseStart', $passage[0])
            ->setParameter('verseEnd', $passage[1])
            ->getQuery()
            ->getResult();
    }

    //    /**
    //     * @return Bible[] Returns an array of Bible objects
    //     */
    //    public function findByExampleField($value): array
    //    {
    //        return $this->createQueryBuilder('b')
    //            ->andWhere('b.exampleField = :val')
    //            ->setParameter('val', $value)
    //            ->orderBy('b.id', 'ASC')
    //            ->setMaxResults(10)
    //            ->getQuery()
    //            ->getResult()
    //        ;
    //    }

    //    public function findOneBySomeField($value): ?Bible
    //    {
    //        return $this->createQueryBuilder('b')
    //            ->andWhere('b.exampleField = :val')
    //            ->setParameter('val', $value)
    //            ->getQuery()
    //            ->getOneOrNullResult()
    //        ;
    //    }
}
