<?php

namespace App\Repository;

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

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

    public function findByRegion(string $region): array
    {
        return $this->createQueryBuilder('filial')
            ->where('filial.address LIKE :address')
            ->setParameter('address', '%' . $region . '%')
            ->orderBy('filial.id')
            ->getQuery()
            ->getResult();
    }
}
