<?php

namespace App\ClinicService\Repository;

use App\ClinicService\Entity\ItemGroup;
use App\ClinicService\Entity\ServiceItem;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

    public function findByUuid(string $uuid): ?ItemGroup
    {
        return $this->findOneBy(['uuid' => $uuid]);
    }

    /** @return ItemGroup[] */
    public function findForService(ServiceItem $service): array
    {
        return $this->createQueryBuilder('g')
            ->where('g.service = :service')
            ->setParameter('service', $service)
            ->orderBy('g.sortOrder', 'ASC')
            ->addOrderBy('g.name', 'ASC')
            ->getQuery()
            ->getResult();
    }
}
