<?php

namespace App\ClinicService\Repository;

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

class ServiceSectionRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, ServiceSection::class);
    }

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

    public function findByEntity(string $entityType, int $entityId): array
    {
        return $this->createQueryBuilder('s')
            ->where('s.entityType = :type')
            ->andWhere('s.entityId = :id')
            ->setParameter('type', $entityType)
            ->setParameter('id', $entityId)
            ->orderBy('s.name', 'ASC')
            ->getQuery()
            ->getResult();
    }

    public function save(ServiceSection $section): void
    {
        $this->getEntityManager()->persist($section);
        $this->getEntityManager()->flush();
    }

    public function remove(ServiceSection $section): void
    {
        $this->getEntityManager()->remove($section);
        $this->getEntityManager()->flush();
    }
}
